Skip to content
Advertisement

Determine programmatically if a program is running

In C, how can I find out programmatically if a process is already running on Linux/Ubuntu to avoid having it start twice? I’m looking for something similar to pidof.

Advertisement

Answer

You can walk the pid entries in /proc and check for your process in either the cmdline file or perform a readlink on the exe link (The following uses the first method).

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement