1

In C program in linux, we can use getpid() and getppid() system call to get the pid and ppid of a process,

Similarly is there any system call to get name of a process/current process?

Jeyaram
  • 9,158
  • 7
  • 41
  • 63
Ravi Chandra
  • 1,749
  • 4
  • 13
  • 22

3 Answers3

5

You can have a look at the /proc/$pid/cmdline file (open it like a normal file and read the zero-byte-delimited command line from it).

That's the way the Unix tool ps does it on Linux.

Alfe
  • 56,346
  • 20
  • 107
  • 159
0

one simple way to know the current executable name is argv[0], which tells you the name of the current executable in C.

Nayan
  • 3,014
  • 2
  • 17
  • 33
Celestial
  • 49
  • 3
0

More solutions can be found here: How to get current process name in linux?

I implemented the solution using the program_invocation_name variable.

Community
  • 1
  • 1
Markus
  • 64
  • 3