Pgrep for processes which are not associated with a terminal in Ubuntu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pgrep for processes which are not associated with a terminal in Ubuntu
# 1  
Old 12-11-2016
Pgrep for processes which are not associated with a terminal in Ubuntu

I would like to find all of the PIDs of processes which are not associated with a terminal and started by CRON.

When I do the ps aux | less command, I see in the TTY field a lot of processes with ? character

I would like to get those processes ID, is there a way to do that with pgrep?

I tried looking at the documentation but it's not very clear...
# 2  
Old 12-11-2016
CRON jobs are never associated with a terminal, but there are processes without a terminal that are not CRON jobs.
Find the PID of the "cron" daemon
Code:
pgrep -o -x -u 0 cron

Now find the PIDs of its children
Code:
pgrep -P <pid_of_cron_daemon>

All in one
Code:
pgrep -P `pgrep -ox cron`


Last edited by MadeInGermany; 12-11-2016 at 06:28 AM.. Reason: added -u 0
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Echo/kill pgrep

Hi folks. I'm wondering why the following doesn't work and hoe to fix it... I can: # pgrep foo 1234 I can: # echo | pgrep foo 1234 But I can't # kill | pgrep foo kill: usage: blah blah So why does echo pipe correctly but kill doesn't? (9 Replies)
Discussion started by: MuntyScrunt
9 Replies

2. UNIX for Beginners Questions & Answers

Connection between terminal and processes

Hello! I've just started to read System V Interface Definition and came across this entry: "Background Process Group A background process group is any process group that is a member of a session which has established a connection with a controlling terminal that is not in the foreground process... (2 Replies)
Discussion started by: saeed13r
2 Replies

3. Shell Programming and Scripting

Pgrep not showing desired output

I am searching for a process that should be up and running. Im using the following command ps -ef | grep elasticsearch to get elastic+ 1673 1 0 Jan29 ? 05:08:56 /bin/java -Xms4g -Xmx4g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

4. Ubuntu

Error starting terminal in Ubuntu 14.04.3

I am unfamiliar with below error and how to fix it, it happens when I start the terminal in Ubuntu 14.04.3. I do not send any command only press crtl+alt+T. It seems to indicate that something is missing from PATH but I’m not really sure what. Thank you :). Command 'lesspipe' is... (24 Replies)
Discussion started by: cmccabe
24 Replies

5. Homework & Coursework Questions

Display info about users (UID GID processes terminal)

I would like to get an opinion for my solution for this task and get feedback about better approach or mistakes I have made. 1. The problem statement, all variables and given/known data: The task is to create a script which prints information about users whose names are specified in the... (2 Replies)
Discussion started by: kornfan
2 Replies

6. Shell Programming and Scripting

Ssh and pgrep not working

I have setup SSH keys . Trying to grep to get PID of remote jvm's . this is what am doing ssh -q testuser1@myhost.com 'PID1=pgrep -fl testapp1|awk "{print $1}";PID2=pgrep -fl testapp2|awk "{print $1}" ' echo $PID1, $PID2 it throws error"sh: -fl: command not found" ---------- Post updated... (1 Reply)
Discussion started by: kondagadu
1 Replies

7. UNIX for Dummies Questions & Answers

I'm unable to run Keyed List commands(in ubuntu's terminal and Evolane Tcl Engine)

I'm trying to run these commands (keylset,keylget) but i keep getting a error message "invalid command name "keylset"". I've tried running it on both ubuntu's terminal and also Evolane Tcl Engine. Any idea what could be the problem? (1 Reply)
Discussion started by: abe171
1 Replies

8. UNIX for Dummies Questions & Answers

PGREP Arguments

I'm trying to figure out how to use pgrep to pull the arguments of a process. Given: root 308 1 0 00:00 ? 00:00:00 /bin/sh /some/random/path/somescript.sh -flag /another/path/blahI can get the pid (308) using this command: pgrep shHowever, what if I wanted to pull by "somescript.sh"... (4 Replies)
Discussion started by: mrwatkin
4 Replies

9. Programming

pgrep returns 256

Hi Everyone, I have a strange behaviour In my c program i use this line: int retval = system("pgrep encoder"); while i expect retval to contain 0,1,2,3 i get 256. did i do something wrong? thanks, Alex (2 Replies)
Discussion started by: alex889
2 Replies

10. UNIX for Dummies Questions & Answers

concurrent terminal connections and processes

we've got solaris 5.6 installed in a ultra 5 box that serves as gateway server going to the main unix box. just like to find out how to determine the number of concurrent terminal connections and processes that the ultra 5 box can handle? and handling at present time? thanks in advance! (1 Reply)
Discussion started by: eddie_villarta
1 Replies
Login or Register to Ask a Question