View Full Version : Start and Stop program
saj0577
April 13th, 2008, 07:42 PM
After looking at compiz-switch/ (http://tombuntu.com/index.php/2008/01/07/toggle-desktop-effects-with-compiz-switch/) i decided i wanted to make a simple program that does the following.
Checks to see if a program is running (i.e apache, amsn)
If its running stops it if its not running starts it.
What language would be best to do this and how would i go about doing this. i.e checking if a program is running.
Saj
nanotube
April 14th, 2008, 12:41 AM
After looking at compiz-switch/ (http://tombuntu.com/index.php/2008/01/07/toggle-desktop-effects-with-compiz-switch/) i decided i wanted to make a simple program that does the following.
Checks to see if a program is running (i.e apache, amsn)
If its running stops it if its not running starts it.
What language would be best to do this and how would i go about doing this. i.e checking if a program is running.
Saj
seems that this is a good job for a shell script. something along the lines of the code below should do the trick:
if $(ps ax |grep 'yourprogram' |grep -v 'grep'; then
pkill 'yourprogram'
else
/path/to/yourprogram &
ghostdog74
April 14th, 2008, 02:33 AM
#!/bin/bash
if [ ! -z "$(pidof program)" ] ;then
pkill program
else
/path/program &
fi
Jussi Kukkonen
April 14th, 2008, 01:28 PM
Plain killing may work, but the right way to do something like this is to use start_stop_daemon with PIDFILE -- take a look at just about any startup script in /etc/init.d (hal should be a good example).
saj0577
April 14th, 2008, 02:06 PM
Cheers.
Saj
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.