> some_interesting_job.py & > process_id=$(ps -o "%p %c" | grep "some_interesting_job" | cut -f 1 -d ' ');\ while [[ -e /proc/$process_id ]];\ do ps -o "%z";\ sleep 5;\ doneThis will report on the virtual memory size (in KiB - see 'ps' manpage for more details) that the process is taking up. The while loop will terminate when the process completes (or is killed).
This is mainly somewhere for me to dump interesting tidbits of tech info. Stuff that I may forget but will need again in the future. For a proper blog, visit my electronics blog (http://www.fangletronics.com) or my wife's pre-school crafty blog (http://www.filthwizardry.com).
Monday, February 11, 2013
Bash: while [[ -e /proc/$process_id ]]
Sometimes you need to keep track of the amount of memory a process is taking up (or CPU, or something else). The /proc filesystem contains a subdirectory for each running process; the directory is named with the pid of the process. You can use this fact along with a basic file test and a while loop to track a process for as long as it lives.
No comments:
Post a Comment