I have a program written in C#, running on Linux using Mono. The program writes its PID to a file. Now I want to check wether a process with this PID is running on start up. Is there a way using Mono? If not, how can I accomplish this using standard Linux functions/tools? Or do I have to check /proc/PID/cmdline?
Asked
Active
Viewed 2,991 times
2 Answers
2
Standard functionality would be to run kill -0 PID
to see if the process is running and check the exit code, 0 function is running.

Anders
- 6,188
- 4
- 26
- 31
1
You could also check that the directory /proc/$PID exists (no need to execute system commands). Should work on Linux, dunno if on other flavors of Unix.
And there is also: System.Diagnostics.Process.GetProcessById(int id)
which should throw an exception if the process with given id is not running. Dunno if it works on Mono.

stalker
- 1,300
- 1
- 13
- 16