diff --git a/src/Process.cpp b/src/Process.cpp index 5145723..544a1b1 100644 --- a/src/Process.cpp +++ b/src/Process.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "WordExp.hpp" @@ -49,6 +50,12 @@ namespace nanosm { for(usize i = 0; i < exp.words.size(); ++i) argv[i] = exp.words[i].data(); + // Ensure that if nanosm (the parent) dies, we die along with it + if(prctl(PR_SET_PDEATHSIG, SIGTERM) == -1) { + perror("Process pre-exec: prctl(PR_SET_PDEATHSIG)"); + exit(1); + } + exit(execvp(exp.words[0].data(), argv.data())); } else { // Parent: monitor the pidfd by adding ourselves to the event loop now