On Thu, 2008-10-16 at 15:56 -0700, Antonio Olivares wrote: > Dear fellow Fedoreans, > > How can I make sure that only one instance of gkrellm runs. When I start one of my machines run several instances of gkrellm. I chose in the configuration run only one, but that does not work :( > > [olivares@localhost ~]$ whoami > olivares > [olivares@localhost ~]$ top > top - 17:51:33 up 1:36, 4 users, load average: 0.36, 0.50, 0.68 > Tasks: 130 total, 1 running, 129 sleeping, 0 stopped, 0 zombie > Cpu(s): 4.7%us, 1.0%sy, 0.0%ni, 94.4%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st > Mem: 773348k total, 712732k used, 60616k free, 23792k buffers > Swap: 3114416k total, 80k used, 3114336k free, 398188k cached > > PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND > 2440 root 20 0 216m 63m 7200 S 3.3 8.4 6:00.98 Xorg > 2986 olivares 20 0 23088 9832 6528 S 1.0 1.3 0:55.45 gkrellm > 3008 olivares 20 0 23056 9868 6556 S 1.0 1.3 0:54.94 gkrellm > 2944 olivares 20 0 103m 23m 15m S 0.7 3.1 0:18.71 plasma > 2968 olivares 20 0 23088 9832 6528 S 0.7 1.3 0:55.39 gkrellm > 2978 olivares 20 0 23088 9828 6528 S 0.7 1.3 0:55.75 gkrellm > 2993 olivares 20 0 23088 9836 6528 S 0.7 1.3 0:55.34 gkrellm > 3000 olivares 20 0 23088 9832 6528 S 0.7 1.3 0:55.55 gkrellm > 554 root 15 -5 0 0 0 S 0.3 0.0 0:04.96 scsi_eh_1 > 2936 olivares 20 0 60492 16m 12m S 0.3 2.2 0:07.61 kwin > 20164 olivares 20 0 73576 15m 11m S 0.3 2.0 0:00.27 konsole > 1 root 20 0 2016 848 636 S 0.0 0.1 0:04.38 init > 2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd > > As you can see there are several gkrellm's running :( > > Cameron shared a script with me: > > #!/bin/bash > # > pidfile=$HOME/.grkrellm.pid > if [ -s "$pidfile" ] && pid=$(<"$pidfile") && kill -0 "$pid" 2>/dev/null > then > echo GKrellM already running, pid=$pid, not starting a new one. > else > gkrellm & # start gkrellm > echo $! >"$pidfile" # save the pid > fi > > > And it finds that gkrellm is already running so it quits. The script works, but I have to find a way to eliminate the extra gkrellm's. > How can I prevent the other gkrellm's and run only one? 1) You don't say how you run the script. 2) What does "kill -0" do? "man kill" doesn't mention this possibilty. 3) The script has an obvious race condition, (i.e. if run from several places simultaneously, there is a non-zero probability of starting more than one process). This is because running the process and creating the pidfile are two separate actions. poc -- fedora-list mailing list fedora-list@xxxxxxxxxx To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines