How do I check if a process is running or not?

Hello Everyone

I have an embedded system running monta vista linux that on bootup may or may not run a process called X. The name of this process is always the same but the process ID might vary/change.

If its not running it can be created anytime by the user through a webbased GUI from a PC running Windows. In addition the user may have a control application running on the PC and he/she can start process X from the control application as well. There MUST only be one instance of process X running at anytime on this system.

So now for my question: How do I in an easy way check if process X is running or not when for example trying to start it using the control application? It might already have been started using the Web GUI or even at bootup?

I have though I could use the 'ps' command and try to capture the output and then parse it for the process name X but I feel that there must be some better way of doing it. Parsing can take time and I also need to alocate a buffer for storing the data before parsing. The size of this buffer has to be big enough to handle the worst case number of processes and that will wast my precious memory(embedded 4MB).

Any input would be great.

Regards Andreas

Reply to
Andreas
Loading thread data ...

Hi Andreas,

andreas snipped-for-privacy@hotmail.com (Andreas) schrieb in news: snipped-for-privacy@posting.google.com:

What about using the /proc directories containin g information about running perocesses? The only problem i see is synchronisation. Another aproach might be using a tcp or udp-port as server which then indicates the running process.

Regards, Kurt

--
PiN - Präsenz im Netz GITmbH
Kurt Harders
http://www.pin-gmbh.com
Reply to
Kurt Harders

Perhaps like that:

The process locks file.

If it can't lock it, another instance e is already running and the process finishes.

-Michael

Reply to
Michael Schnell

Hello Michael,

I normally use a little utility ?TOP? on my development system to find out what exectly is happening on the system.

Man top : will give you full detail. (top - display Linux tasks)

Also most of the time i create a log file of the PID when i fork them in application so i can keep trace of all the process i am starting.

Regards'

Rushi

Reply to
Rushi

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.