launching a process if it doen't exist (Folding@HOME)
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Since you've got +500 posts here's a clue. Call the script something easy like "fahctl" and run it like "sh -x <filename>" to see if it suits your purposes and works properly.
No Bash manuals where hurt during this exercise, void where probibited by shell/law, no funds returned after running, warranty void before publication, no tinkering on premises and YMMVVM as usual.
#!/bin/sh
# warning: nasty obfuscation and array abuse ahead :-]
pid=($(/sbin/pidof FAH3Console.exe) $HOME/Folding/Console.pid $HOME/Folding/FAH3Console.exe "FAH3Console: ")
msg=(echo "already running" "stopped but pidfile exists" "already stopped" "running but pidfile went limbo" "$(basename $0) [start|restart|stop]" stopped)
s() { if [ -f "${pid[1]}" -a "${pid[0]}" != "" ]; then ${msg[0]} ${msg[1]}; exit 0; fi; if [ -f "${pid[1]}" -a "${pid[0]}" = "" ]; then ${msg[0]} ${msg[2]}; rm -f ${pid[0]}; fi; ${pid[2]} > /dev/null &; # if it doesn't put it's PID in $pidf, use: ${pid[0]} > $pidf; }
k() { if [ ! -f "${pid[1]}" -a "${pid[0]}" = "" ]; then ${msg[0]} ${msg[2]}"; exit 0; elif [ -f "${pid[1]}" -a "${pid[0]}" = "" ]; then ${msg[0]} ${msg[1]}; rm -f ${pid[1]}; exit 0; else if [ ! -f "${pid[1]}" -a "${pid[0]}" != "" ]; then ${msg[0]} ${msg[4]}; kill -s TERM "${pid[0]}"; else kill -s TERM "${pid[0]}"; rm -f ${pid[1]}; ${msg[0]} ${msg[6]}; fi; fi; }
Thnx, I'm trying to raise my Bash scripting mana so I can't shun writing scripts. Heh, no. On second thought I'd consider myself having a lucky case of CSD or Compulsory Scriptwriting Disorder... Which is way better than having a MTD: Microsoft Transmitted Disease :-]
Btw[0], you only check for pidfile existence (-e) but this app could leave a pidfile and not be running right?
Btw[1], if you ran the script like I said as "sh -x <filename>" You'd see *exactly* what it does. It ain't a mistery.
Yes, it's an optimisation prob.
If another user logs on and the .pid file exists, it won't generate a new process. But when the original owner logs off, the process stops and there's no Folding process running anymore. Hmmm.
I'm thinking of changing ownership of a global file, so that the most recent user to login gets ownership of FAHowner.id file. When the user exits, check if they own the file. If they do, kill the process. If they don't leave it running.
This scenario doesn't cater for multiple logins from a single user though. Aaagh!
The other option is of course just to have multiple processes (one for each user) but then ... well, there's not much point in having this script. Hmmm.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.