Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current process name in linux?

Tags:

c

linux

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?

like image 524
Mariusz Avatar asked Feb 01 '12 14:02

Mariusz


People also ask

How do I see current processes in Linux?

You can list running processes using the ps command (ps means process status). The ps command displays your currently running processes in real-time.

How get PID details in Linux?

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.

How do I find the PID process name?

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.


1 Answers

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]

like image 97
Pierre Habouzit Avatar answered Oct 06 '22 16:10

Pierre Habouzit