Hello, On Sun, 14 Feb 2010, Carlos E. R. wrote:
On Sunday, 2010-02-14 at 02:00 +0100, David Haller wrote:
On Sat, 13 Feb 2010, Carlos E. R. wrote:
You and Dave are correct. I must have been tired :-)
Dave, picky, picky :p. 'echo "$$" > $runfile' is better, because you
;)
"echo" should be faster than calling external program "touch", thus the preference - if I understand correctly.
No. You could go and get the pid from the runfile and kill the script with that. I.e.: test -f RUNFILE && kill $(< RUNFILE ) && rm -f RUNFILE
Sorry, I don't understand a word. Could you please explain for non bash gurus?
Ok. When the script starts, you save the PID of the bash running the script in the pidfile (called RUNFILE above). Let's use a better name: /var/run/dslwatchdog.pid. You can use that file to get the PID of the (supposedly running) script and then kill that script. Or check if the script still runs, get a bunch of data from /proc/PID/ etc. pp. Above code, written differently: ==== PIDFILE="/var/run/dslwatchdog.pid" if test -f "$PIDFILE" ; then ### is the pidfile a file? watchdog_pid=$( cat "$PIDFILE" ) ### read the PID from the file if kill $watchdog_pid ; then ### kill the watchdog and if ### successful rm -f "$PIDFILE" ### remove the pidfile fi fi ===== The '$(< FILE)' is a bashism to read the content of a file into the commandline without using external commands. I.e. echo $(< FILE) is equivalent to echo $(cat FILE) just without the cat (which takes a lot of time to start in comparison). It may not seem like much, but starting external programs is expensive and _does_ add up. Look at (older) teTeX scripts like mktexnam and alike. Those actually are right to call external programs, as they're /bin/sh scripts and are/were supposed to run under a lot of shells and systems. Ah, and yes, most daemons have a pidfile in /var/run/ for a reason. Such as the ability to check if the daemon already runs (i.e. read the pidfile, look, if there's the daemon already/still running with that pid (look at /proc/${pid}/cmdline ;) or if it ended uncleanly without being able to remove the pidfile). Or whatever ;) Usually, on SUSE, services are started/checked/stopped via startproc/checkproc/killproc, which uses pidfiles "out of the box" and under a configurable name (-f option, so you can run a service more than once, with different pidfiles, say daemon_for_host_foo.pid and daemon_for_host_bar.pid). More questions? Call 0900-..., aaah, ask again! ;) -dnh -- "DOS=HIGH ...I knew it was on something!" (UNIX user, while reading C:\CONFIG.SYS) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org