kphp
kphp copied to clipboard
Possibility to set process name
I would suggest the possibility of setting the process name (as seen by ps or top) of master and workers via two options to the server process:
--worker-procname "Somename [worker]" and --master-procname "Somename [master]"
as done in this C code below:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <errno.h>
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <NewName>\n", argv[0]);
return EXIT_FAILURE;
}
char *new_name = argv[1];
// Ensure the new name is not longer than 15 characters
if (strlen(new_name) > 15) {
fprintf(stderr, "Error: Process name cannot be longer than 15 characters\n");
return EXIT_FAILURE;
}
// Change the name of the current process
if (prctl(PR_SET_NAME, (unsigned long)new_name, 0, 0, 0) != 0) {
perror("prctl(PR_SET_NAME)");
return EXIT_FAILURE;
}
printf("Successfully changed the name of the current process to %s\n", new_name);
while (1) {
sleep(1); // Keep the process running to observe the name change
}
return 0;
}
I thought this was what the --master-name option did, but apparently not...
(what exactly does the --master-name option do ?)