LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash Script - How do I make sure my program is still running? (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-how-do-i-make-sure-my-program-is-still-running-357263/)

nro 08-26-2005 11:53 AM

Bash Script - How do I make sure my program is still running?
 
Hello,
I have minimal(almost no) experience with linux and have ssh to a server with minimal access.
My objective is to keep a program running. If the server shuts down then it will stop. I want to make sure it stays live. I would appreciate any help with this.

Just a note: I don't really know anything about cron jobs, just that they exist. Would this be a solution?

Thanks,
Mike

abisko00 08-26-2005 11:59 AM

I think I remember to have used 'nohup <command> &'. This should run the command independent from the existence of the console you used to start it.

nro 08-26-2005 12:19 PM

How do I stop a command like that?

abisko00 08-26-2005 12:33 PM

You need to know the process ID (e.g. ps ax | grep <command>). Then you can send the stop signal with e.g. 'kill -19 <pid>'. -19 is equivalent to SIGSTOP, but there are many others (see 'kill -l'). I don't know which is to prefer.

ghrellin 08-28-2005 01:57 PM

An even easier way to get the process ID (PID) of your program is to do
Code:

ps -C [program name]
Then you can kill it if you want. Also, nohup [command] & just directs all output to nohup.out (the nohup part) and makes it run in the background (the &). To bring the program back from the background, you can type
Code:

fg [command name]
and to see which programs you started with &, type jobs. Whew. Little process control tutorial there.


All times are GMT -5. The time now is 01:59 AM.