LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Check if an app is running and if it's not launch this app (https://www.linuxquestions.org/questions/linux-general-1/check-if-an-app-is-running-and-if-its-not-launch-this-app-186913/)

Coume 05-28-2004 08:43 AM

Check if an app is running and if it's not launch this app
 
Hello,

I have one thing that I Would like to do but I do not know if there is a way to do that or not...

I'd like to check every 5 mins or 10, if a specific app is running and if it's not, I would like to launch it.

Do you think such thing is possible? and if yes, I should look at which programming language??

Thxs in advance
Ludo

SBing 05-28-2004 09:54 AM

Sure sounds very possible, you could get something to run every x minutes using cron, just with multiple crontab entries in the minute field (so run @ 5, 10, 15 ...0).

To check if the program is running, you could try:

ps -A | grep <process> | grep -v grep

and get a shell script to test output for a certain string.

I know that's a bit vague but I think it's a good way to do it of the top of my head, there may be much better ways though that might be suggested by other people.

Maybe if you give us a bit more info on which program you want to run we might be able to help you more :)

Steve

Coume 05-28-2004 09:58 AM

thxs for the answer :)

that would be for checking if amule is working or not :rolleyes:

Ludo

Micky_123 07-28-2008 02:34 AM

Hi,

pgrp can help you.
Use prep -x <Name of the process>.

Also, You can search for the process name in the /proc/pid/stat. If you find the process name there, you don't need to start the process again otherwise you can start the process again. For starting the process, you can either use fork or system("<process name>").

I believe you can achieve your goal in script as well as after writing a small C program.

cheers,
Micky


All times are GMT -5. The time now is 03:41 PM.