From cf89b3457feaa7f7695fc992d25473f773423008 Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Wed, 16 Aug 2017 20:36:09 -0400 Subject: Initial commit --- example.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 example.c (limited to 'example.c') diff --git a/example.c b/example.c new file mode 100644 index 0000000..b822312 --- /dev/null +++ b/example.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include + +int main() { + int pipefd[2]; + if (pipe(pipefd)) { + perror("pipe"); + exit(1); + } + + if (fork()) { + close(pipefd[0]); + fcntl(pipefd[1], FD_CLOEXEC); + + // do work + puts("Working..."); + sleep(10); + + // works even if process dies! + kill(getpid(), SIGKILL); + } else { + close(pipefd[1]); + close(0); + dup2(pipefd[0], 0); + execl("./inhibit-screensaver", "./inhibit-screensaver", "c-inhibitor-example", "testing", (char *)NULL); + exit(1); + } +} -- cgit v1.2.3-54-g00ecf