2

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
  • 8,727
  • 6
  • 38
  • 61
Ravi Chandra
  • 1,611
  • 4
  • 13
  • 21

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
  • 52,016
  • 18
  • 95
  • 150
1

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,018
  • 2
  • 15
  • 32
Celestial
  • 41
  • 3
1

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
  • 66
  • 3