Little script to identify child process
I've got a script that loops through a list of directory names and compresses them. There are lots and once in a while I want to check on the progress and find out which directory in the list it's working on.
The name of the script is compress.sh, tar will run as a child of it, which I can locate using the parent PID:
me@my:~$ show.proc.sh compress.sh USER TT PID PPID %CPU %MEM VSZ STARTED TIME COMMAND me pts/19 1810 24357 0.0 0.0 4496 10:15:37 00:00:00 | \_ /bin/bash ./compress.sh me pts/19 1857 1810 0.5 0.0 3696 10:16:03 00:00:01 | | \_ tar cfj 833444.tar.bz2 833444
1 2 3 4 5 6 7
#!/bin/bash # get pid pid=$(pgrep $1) ps axfo user,tty,pid,ppid,pcpu,pmem,vsz,start,time,args | head -1 ps axfo user,tty,pid,ppid,pcpu,pmem,vsz,start,time,args | grep $pid | grep -v grep
1 2 3
#!/bin/bash for d in $(cat dir.list.2010-05-11); do tar cfj $d.tar.bz2 $d && rm -rf $d; done