I've been using the (super! cool! long-awaited!!) new server_stats facility in DART 6.0 to collect all kinds of cool stuff. I'm trying to build a script to collect statistics via cron, then run a cron script to kill the server_stats collection.
My problem is, when I kill or pkill the parent pid of my script, it doesn't kill all of the child processes, because a new child seems to be forked by the undelying Java. Let's what my pax-script in action:
[nasadmin@NS80-CS0 scripts]$ ./start-pax-stats.sh (I capture the PID in this script, and write it as /tmp/paxstat.pid) [nasadmin@NS80-CS0 scripts]$ cat /tmp/paxstat.pid 15996 [nasadmin@NS80-CS0 scripts]$ ps -ef|grep stats nasadmin 15996 18335 0 13:04 pts/0 00:00:00 /bin/bash ./start-pax-stats.sh nasadmin 16000 15996 0 13:04 pts/0 00:00:00 /bin/sh /nas/bin/server_stats server_2 -monitor ndmp.pax.session.ALL-ELEMENTS.dataOperator.ALL-ELEMENTS.backupRootDir,ndmp.pax.session.ALL-ELEMENTS.dataOperator.ALL-ELEMENTS.bytes -interval 5 -te no -format csv -file /nas/quota/slot_2/ndmp_logs/pax/pax.1101131304 nasadmin 16002 16000 19 13:04 pts/0 00:00:03 /usr/java/bin/java -DNAS_DB=/nas -server -Xmx256M -cp /nas/stats/lib/server_stats.jar:/nas/http/webui/tools/tomcat/webapps/ROOT/WEB-INF/lib/ccmd-support_en_US.jar:/nas/j_lib/db.jar server_stats server_2 -monitor ndmp.pax.session.ALL-ELEMENTS.dataOperator.ALL-ELEMENTS.backupRootDir,ndmp.pax.session.ALL-ELEMENTS.dataOperator.ALL-ELEMENTS.bytes -interval 5 -te no -format csv -file /nas/quota/slot_2/ndmp_logs/pax/pax.1101131304
Now when I pkill the PPID with pkill -P 15996, I get:
Both my script and the forked Java process both have the same name. Worse yet, if I had multiple server_stats instances running (which is highly possible), pkill would kill multiple instances in one go.
Looking for the unique string got me pointed in the right direction! I ended up using 'pgrep' to find the PID of the spawned Java instance and 'pkill' to kill said PID. Worked like a charm.
dynamox
11 Legend
•
20419 Posts
•
87439 Points
1551
0
Posted January 13th, 2011 11:00
your script and java script have "ndmp" in the string ..so is that going to be unique to which object you are monitoring ?