Suppose there is a process dummy.sh whose pid is 101 & has seven descendants:
pstree -pc 101 dummy(101)──dummy(102)──dummy(103)──dummy(104)──dummy(105)──dummy(106)──sleep(107) But how to fetch PID's of all the process in Bash script which has more than six(in our example dummy.sh 101) descendants. I do not want PID's of process whose descendants are less than six.
I tried PS -u myuser but it only displays all user process. But how to get PID's of user processes which have descendants greater than six ?
Update:
For example purpose I use below recursive script to trigger seven straight chain of descendants. I want to get PID 101 as it has more than six descendants.
Similarly as this dummy process is triggered by bash(100) terminal which will be parent to dummy(101) then I want Pid 100 as well (as it also meets the condition of having more than six descendants). bash(100)──dummy(101)──dummy(102).....dummy(107)
#!/bin/bash if [[ "$#" -ne 1 ]]; then set -- 7 fi if [[ "$1" -gt 2 ]]; then echo 'descendant process' "$1" "$0" "$(($1 - 1))" else sleep 500 fi Criteria: I will consider only the PID's returned by ps -u $USER -o pid command. As my requirement is only to consider user preprocess. I will loop them to find if a user process has more than six descendants, but my question is how do i find descendants count for a particular PID ?
smbdprocess with three immediate descendants, i.e. not in a chain. Run this code to output the example as if frompstree-echo 'smbd(1076)─┬─cleanupd(1130)'; echo ' ├─lpqd(1147)'; echo ' └─smbd-notifyd(1126)'. In the context of your question does that count as three descendants, or one descendant three times?