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
If you're getting an "Device or resource busy" error when trying to use to supersede the symbolic link, it means that the process you're trying to change is currently executing code and the operating system is not allowing the path of the executable to be modified while it's in use.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.