Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Callum Kilby's Tutorials and Useful Code | ||||||||
Line: 18 to 18 | ||||||||
then echo 'Usage: kenewRun "COMMAND"' else if [ -z $AKLOG ] | ||||||||
Changed: | ||||||||
< < | then echo 'Please define AKLOG variable to be path to aklog (e.g. /usr/bin/aklog)" | |||||||
> > | then echo 'Please define AKLOG variable to be path to aklog (e.g. /usr/bin/aklog)' | |||||||
else krenew -t -- sh -c "$1" fi |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
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. |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Callum Kilby's Tutorials and Useful Code | ||||||||
Line: 35 to 35 | ||||||||
peakvmem = "0 kB" | ||||||||
Changed: | ||||||||
< < | cat /proc/${!}/status | awk '/VmPeak/{print $2" "$3}' &> tempVmPeak.txt | |||||||
> > | temppeakvmem="$(cat /proc/${!}/status | awk '/VmPeak/{print $2" "$3}')" | |||||||
while [ -z "$(kill -0 $!)" ]; do | ||||||||
Changed: | ||||||||
< < | peakvmem="$(cat tempVmPeak.txt)" cat /proc/${!}/status | awk '/VmPeak/{print $2" "$3}' &> tempVmPeak.txt | |||||||
> > | peakvmem="$temppeakvmem" temppeakvmem="$(cat /proc/${!}/status | awk '/VmPeak/{print $2" "$3}')" | |||||||
sleep 10
done
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. | ||||||||
Changed: | ||||||||
< < | The peakvmem variable is set from tempVmPeak.txt 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. | |||||||
> > | 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. | |||||||
-- CallumKilby - 12 Apr 2016 |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Callum Kilby's Tutorials and Useful Code | ||||||||
Line: 26 to 26 | ||||||||
} | ||||||||
Added: | ||||||||
> > | Cluster job peak memory usage: profiling the peak memory usage of a job run on the clusterIf it is useful to check the peak memory usage of a job that has run on the cluster (e.g. to determine an appropriate memory requirement for your qsub command for future cluster jobs), the following code snippet regularly checks the peak usage up until that moment of a specific process run as part of the cluster job:runYourNiceProcess & #Important that this is run in the background peakvmem = "0 kB" cat /proc/${!}/status | awk '/VmPeak/{print $2" "$3}' &> tempVmPeak.txt while [ -z "$(kill -0 $!)" ]; do peakvmem="$(cat tempVmPeak.txt)" cat /proc/${!}/status | awk '/VmPeak/{print $2" "$3}' &> tempVmPeak.txt sleep 10 doneThis 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.
The peakvmem variable is set from tempVmPeak.txt 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. | |||||||
-- CallumKilby - 12 Apr 2016 |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > |
Callum Kilby's Tutorials and Useful CodeUseful CodekrenewRun: running local jobs without your kerberos/AFS tokens either expiring or being lostAn issue when running jobs locally, particularly in a screen, is that kerberos and AFS tokens can either expire, or in the case of working on lxplus, will be cleared when you log off. To get around this, I use a script calledkrenew . This script generically allows you to start a daemon that copies your current tokens, and periodically refreshes them as desired.
I have made a wrapper for krenew , named krenewRun , to run any command line code passed in, with the tokens copied by krenew being refreshed until the process started by the command line code has finished running. This wrapper also performs a check for whether AKLOG is defined. aklog is the function that deals with AFS tokens, and AKLOG is the path to this function. krenew needs this function when handling your AFS tokens.
To make use of krenewRun , copy the below code into your ~/.bash_profile or ~/.bashrc. Usage is simply krenewRun "COMMAND" , where COMMAND is whatever text you would have entered into your command line, with " marks escaped as \"
krenewRun( ) { if [ "$1" == "-h" ] then echo 'Usage: kenewRun "COMMAND"' else if [ -z $AKLOG ] then echo 'Please define AKLOG variable to be path to aklog (e.g. /usr/bin/aklog)" else krenew -t -- sh -c "$1" fi fi }-- CallumKilby - 12 Apr 2016 |