Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Pause and resume resource-intensive apps via script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Pause and resume resource-intensive apps via script
Authored by: SOX on May 17, '06 08:28:11AM
Replying to my own hint here. it looks like the editor accidentally chopped off the three command line args from the hint. so the three numbers I referred to in the hint were supposed to follow that one line perl script.

A couple notes about that script. The script is polite in that if you break out of it with control-C, it will leave your app in a running state, not suspended. Additionally, if your application quits then the script eventually notices this and terminates itself, thus you can set this to run in the background if you want. It won't bother the script if, in another window you suspend or continue the application, so you still can have some fine grained manual control if you need it. And you can run as many copies of this as you wish to control other applications. Nothing dire will happen if you mistakenly run this twice to control the same job, thought that's not the reccomended use.

Now as for converting this into an alias to make it handy to use, here is a version of it I have escaped all the special characters to allow you to do this easily. Cut and paste the following verbatim into a terminal window--you should do this as one single cut and paste not a line at a time. finish with a carriage return from the keyboard.


alias supernice perl\ \-we\ \'die\ unless\ \@ARGV\;\$SIG\{INT\}\ \=sub\
 \{\`kill\ \-s\ CONT\ \$p\`\;\ die\ qq\:bye\ now\\n\:\}\;\(\$p\,\$s\,\$c\)\
 \=\ \(\ \@ARGV\,2\.5\,0\.5\)\;\(\$sig\,\$w\)\ \=\ \(qq\:CONT\:\,30\)\;\
 \$c1\=\$c2\=\$e1\=\$e2\=0\;\$e2\=30\;while\ \(1\)\ \{\ last\ unless\
 \ grep\{\ \/\^\\s\*\$p\ \/\}\ \`ps\ x\`\;\ \ \(\$x\,\$y\,\$z\)\ \=\ split\
 \/\\s\+\/\,\`sysctl\ vm\.loadavg\`\;\ \ \(\$sig\,\$w\,\$e1\,\$e2\)\
 \=\(qq\:CONT\:\,30\,0\,30\)\ if\ \(\$z\<\$c\)\;\(\$sig\,\$w\,\$e1\,\
 \$e2\)\=\(qq\:STOP\:\,300\,300\,0\)\ if\ \(\$y\>\$s\)\ \;\ \`kill\ \-s\
 \$sig\ \$p\`\ \;\ print\ STDERR\ qq\/\ \$p\:\ \$x\ \$y\ \$z\ \ \ \$sig\
 \ S\:\$c1\ C\:\$c2\ sec\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \/\,chr\(13\)\;\ sleep\
 \$w\;\$c1\+\=\$e1\;\$c2\+\=\$e2\}\'

To use this after installing that alias you would type at the command line


supernice  3357  3.0 0.5
where 3357 is the name of whatever process you want to supernice, and 3.0 is the upper load limit trip where you want it to stop, and 0.5 is the lower load limit trip where you will let it resume after being stopped. Fill in your own numbers as appropriate.

Output from the script will display the number of seconds the job has been stopped and how long it has been running since supernice was invoked. It also displays the load levels for the last 1 minute and last ten minutes. These numbers update every 30seconds when in CONT mode or 5 minutes in STOP mode.

[ Reply to This | # ]