Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change real process name in C on Linux

Tags:

c

linux

process

I'm currently trying to change the process name of a process so I can read the more easily with htop, top, .... I want to LD_PRELOAD this code into another process so it gets renamed by an environemt variable.

I found a lot of stuff in the internet, but nothing works:

prctl(PR_SET_NAME, "Test");

This does not work because htop is not honoring the name.

Nginx setproctitle (Link) doesn't work as well, because it strips the parameters (which are needed by the process).

I tried everything I found and now I'm out of ideas.

Is this even possible in linux? And how?

like image 465
das_j Avatar asked Jul 31 '15 13:07

das_j


People also ask

How get PID process name Linux?

The ps -p <PID> command is pretty straightforward to get the process information of a PID. Alternatively, we can also access the special /proc/PID directory to retrieve process information.

What is process name in Linux?

The process identifier (process ID or PID) is a number used by Linux or Unix operating system kernels. It is used to identify an active process uniquely.

How do you change a process name in Python?

The name for a new process can be set via the “name” argument in the constructor to the multiprocessing. Process class when creating a new process.


1 Answers

Just run your program by shell script or your program through exec and pass desired name as argv[0]:

#/bin/bash
exec -a fancy_name a.out ...

or C/C++:

execl( "./a.out", "fancy_name", ... );
like image 102
Slava Avatar answered Sep 27 '22 21:09

Slava