Medium
FD_CLOEXEC across fork() and exec()
Does the fd for secret.log show up among the exec'd ls process's open file descriptors?
main.cpp
#include <fcntl.h>
#include <unistd.h>
#include <sys/wait.h>
#include <cstdio>
int main() {
int fd = open("secret.log", O_RDONLY);
fcntl(fd, F_SETFD, FD_CLOEXEC);
if (fork() == 0) {
execl("/bin/ls", "ls", "-l", "/proc/self/fd", nullptr);
_exit(1);
}
wait(nullptr);
return 0;
}15 of 53 in Operating Systems