Skip to main content
formatting
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
ps -eo ppid= | grep -Fwc $pid

If your grep does not support -w:

ps -eo ppid= | tr -d '[:blank:]' | grep -Fxc $pid

or ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid

ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid

or (clobbering the positional parameters)

set $(ps -eo ppid=); echo $#

Note that this is not atomic, so the count may be wrong if some processes die and others get spawned in the short span of time it takes to gather the data.

ps -eo ppid= | grep -Fwc $pid

If your grep does not support -w:

ps -eo ppid= | tr -d '[:blank:]' | grep -Fxc $pid

or ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid

or (clobbering the positional parameters)

set $(ps -eo ppid=); echo $#

Note that this is not atomic, so the count may be wrong if some processes die and others get spawned in the short span of time it takes to gather the data.

ps -eo ppid= | grep -Fwc $pid

If your grep does not support -w:

ps -eo ppid= | tr -d '[:blank:]' | grep -Fxc $pid

or

ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid

or (clobbering the positional parameters)

set $(ps -eo ppid=); echo $#

Note that this is not atomic, so the count may be wrong if some processes die and others get spawned in the short span of time it takes to gather the data.

added 246 characters in body
Source Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
ps -eo ppid= | grep -Fwc $pid

If your grep does not support -w:

ps -eo ppid= | tr -d '[:blank:]' | grep -Fxc $pid
 

or ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid

or (clobbering the positional parameters)

set $(ps -eo ppid= | awk '$1==ppid {++i} END {print); i+0}'echo ppid=$pid$#

Note that this is not atomic, so the count may be wrong if some processes die and others get spawned in the short span of time it takes to gather the data.

ps -eo ppid= | grep -Fwc $pid

If your grep does not support -w:

ps -eo ppid= | tr -d '[:blank:]' | grep -Fxc $pid
 
ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid
ps -eo ppid= | grep -Fwc $pid

If your grep does not support -w:

ps -eo ppid= | tr -d '[:blank:]' | grep -Fxc $pid

or ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid

or (clobbering the positional parameters)

set $(ps -eo ppid=); echo $#

Note that this is not atomic, so the count may be wrong if some processes die and others get spawned in the short span of time it takes to gather the data.

Source Link
Barefoot IO
  • 2k
  • 1
  • 14
  • 14

ps -eo ppid= | grep -Fwc $pid

If your grep does not support -w:

ps -eo ppid= | tr -d '[:blank:]' | grep -Fxc $pid

ps -eo ppid= | awk '$1==ppid {++i} END {print i+0}' ppid=$pid