diff --git a/src/cgmemmgr.cpp b/src/cgmemmgr.cpp index d5850b2265013..b0e0c3d79eea6 100644 --- a/src/cgmemmgr.cpp +++ b/src/cgmemmgr.cpp @@ -260,9 +260,16 @@ static int self_mem_fd = -1; static int init_self_mem() { +#ifdef O_CLOEXEC int fd = open("/proc/self/mem", O_RDWR | O_SYNC | O_CLOEXEC); if (fd == -1) return -1; +#else + int fd = open("/proc/self/mem", O_RDWR | O_SYNC); + if (fd == -1) + return -1; + fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif // buffer to check if write works; volatile uint64_t buff = 0; uint64_t v = 0x12345678;