c code of Supersede the /proc/pid/exe symbolic link with prctl
- User
c code of Supersede the /proc/pid/exe symbolic link with prctl
- Assistant
Here's an example of C code that uses the prctl function to supersede the
/proc/pid/exesymbolic link:#define _GNU_SOURCE #include <sys/prctl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <stdbool.h> int main() { // Get the current process ID pid_t pid = getpid(); // Print the current executable file path char exe_path[4096]; ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); if (len == -1) { perror("readlink"); exit(EXIT_FAILURE); } exe_path[len] = '\0'; printf("Current executable file path: %s\n", exe_path); // Supersede the /proc/pid/exe symbolic link char new_exe_path[] = "/path/to/new/exe"; if (prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, new_exe_path, 0, 0) == -1) { perror("prctl"); exit(EXIT_FAILURE); } // Verify the new executable file path len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); if (len == -1) { perror("readlink"); exit(EXIT_FAILURE); } exe_path[len] = '\0'; printf("New executable file path: %s\n", exe_path); return 0; } - User
it doesn't work, error is device is busy
- Assistant