Difference: CallumKilbyTutorialsAndUsefulCode (3 vs. 4)

Revision 415 Feb 2017 - CallumKilby

Line: 1 to 1
 
META TOPICPARENT name="PP/Computing.WebHome"

Callum Kilby's Tutorials and Useful Code

Line: 35 to 35
  peakvmem = "0 kB"
Changed:
<
<
temppeakvmem="$(cat /proc/${!}/status | awk '/VmPeak/{print $2" "$3}')" while [ -z "$(kill -0 $!)" ]; do
>
>
pid=$! temppeakvmem="$(cat /proc/${pid}/status | awk '/VmPeak/{print $2" "$3}')" while [ -e /proc/$pid ]; do
  peakvmem="$temppeakvmem"
Changed:
<
<
temppeakvmem="$(cat /proc/${!}/status | awk '/VmPeak/{print $2" "$3}')"
>
>
temppeakvmem="$(cat /proc/${pid}/status | awk '/VmPeak/{print $2" "$3}')"
  sleep 10 done
Changed:
<
<
This works by accessing /proc/PID/status to find information about your process (which has a process id of PID). ${!} returns the PID of the last process put in the background, and /proc/PID/status is the direct output of various statuses of this process, including peak memory usage. kill -0 $! won't actually do anything, but will return an empty string if the process exists, and a "No such process" error if the process does not exist.
>
>
This works by accessing /proc/PID/status to find information about your process (which has a process id of PID). $! returns the PID of the last process put in the background, and /proc/PID/status is the direct output of various statuses of this process, including peak memory usage.
  The peakvmem variable is set from temppeakvmem to avoid the (hopefully unlikely) scenario that the process ends between the while condition check and /proc/PID/status being read, as the /proc/PID folder will disappear once the process has ended. As such, you would just get a "No such file or directory" error if you tried to access /proc/PID once the process has finished.
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback