Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

401
Views
Change real process name in C on Linux

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?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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", ... );
over 4 years ago · Santiago Trujillo Report

0

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define NEW_NAME "hello_world"
int main(int argc, char **argv) {
  if(strcmp(argv[0], NEW_NAME)) {
    argv[0] = NEW_NAME;
    execv("/proc/self/exe", argv);
    fputs("exec failed", stderr); 
    return 1;
  }
  while(1) // so it goes to the top
    ;
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!