Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #check if the number of arguments is right
- if [ $# -ne 1 ]
- then
- echo "USAGE: `basename $0` korisnik"
- exit 1
- fi
- #check if the out.txt file already exists
- if [ -f out.txt ]
- then
- rm out.txt
- fi
- #create the out.txt file
- touch out.txt
- echo "PID|Number of kids" >> out.txt
- #get all process IDz of all the processes the argument user has started
- pids=`ps -es | grep ^$1 | awk 'print $2;'`
- #go thru all of em
- for pid in $pids
- do
- count=0
- #get the parent process IDz of the processes the user had started
- ppids=`ps -es | grep ^$1 | awk 'print $3;'`
- #if the process the user started is a parent of some other process then count++
- if [ $pid -eq $ppid ]
- then
- count=`expr $count + 1`
- fi
- #put in a line of text in out.txt for every cycle iteration
- #that consists of the PID of each process the user had started
- #and tha number of his child processes separted with tha | symbol
- echo "${pid}|${count}" >> out.txt
- done
- #print on screen tha output in need
- cat out.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement