blob: b82231242f6d000f34be4c601dd8ae39c8f1466c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
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);
}
}
|