How can I get the process name in C? The same name, which is in /proc/$pid/status
. I do not want to parse that file. Is there any programmatic way of doing this?
You can list running processes using the ps command (ps means process status). The ps command displays your currently running processes in real-time.
A process is nothing but running instance of a program and each process has a unique PID on a Unix-like system. The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column. Click on any column name to sort. You can right click a process name to see more options for a process.
If you're on using a glibc, then:
#define _GNU_SOURCE #include <errno.h> extern char *program_invocation_name; extern char *program_invocation_short_name;
See program_invocation_name(3)
Under most Unices, __progname
is also defined by the libc. The sole portable way is to use argv[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With