Diff between "ps -ef"and "ps -eo"

Hi, have to list current running processes (including sub-processes/child processes). im using ps -eo etime,pid,cmd | grep "process_name"
But sometimes, the command is not listing the sub-processes. I assume all processes (processes and sub-processes ) are listed only with ps -ef command, but not with my ps -eo command mentioned above.

Please clarify.

None, except output formatting
From the linux man page for ps(1)

      To see every process on the system using standard syntax:
          ps -e
          ps -ef
          ps -eF
          ps -ely

       To see every process with a user-defined format:
          ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
          ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm

Your problem is what the grep statement does to output. Process names for a subprocess do not necessarily display the same when you specify output fields. Plus, sub-processes may come and go rapidly. ex: when you execute a shell script with commands like: ls, awk, grep, etc. Sub-processes do not have to have the same runtime duration as the parent.

To get a completely correct answer, please help us with:
Exact OS name ( uname -a )

Edit:
Consider using the process tree (Linux example):

# To print a process tree:
          ps -ejH
1 Like

Thanks for the reply.

Can i search this way to list sub-processes :
ps -eo etime,pid,cmd | grep "sub-process_name"

Here is the output of uname -a command:
Linux DG10 2.6.18-308.13.1.el5 #1 SMP Thu Jul 26 05:45:09 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

And how do you find the "sub-process-name"? It needs to be a two-step approach - first find the parent process in question, then, with its PID, find all processes whose PPID (parent PID) is PID.
What about sub-subprocesses?

sub-process execute commands include dsjob -run .

so, can i search this way:
ps -eo etime,pid,cmd | grep "dsjob.*run"

ps -ef displays args, so try

ps -eo etime,pid,args | grep "[d]sjob.*run"

The [ ] trick prevents from matching the grep process argument.

1 Like

Could you use pgrep?

ps -l -p$(pgrep -d, process_name)

will list all processes named "process_name"
You want sub-processes of "process_name"?

ps -l --ppid $(pgrep -d, process_name)

And work from there.

Andrew

1 Like