Skip to content

Instantly share code, notes, and snippets.

@isometry
Created January 20, 2018 21:40
Show Gist options
  • Save isometry/4a90ae1014736fbb4c86abdb8d2c4796 to your computer and use it in GitHub Desktop.
Save isometry/4a90ae1014736fbb4c86abdb8d2c4796 to your computer and use it in GitHub Desktop.
Fake the process name of an arbitrary command to help distinguish between multiple concurrent instances
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void usage(char *name);
int
main(int argc, char *argv[])
{
char *rexec;
char *nargv[argc-1];
int i;
if (argc < 3)
usage(argv[0]);
nargv[0] = argv[1];
rexec = argv[2];
for (i = 1; argv[i+2]; ++i)
{
nargv[i] = argv[i+2];
}
nargv[i] = '\0';
exit(execvp(rexec, nargv));
}
void
usage(char *name)
{
fprintf(stderr,"USAGE: %s mask real [arguments ...]\n", name);
exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment