summaryrefslogtreecommitdiff
path: root/example.c
diff options
context:
space:
mode:
Diffstat (limited to 'example.c')
-rw-r--r--example.c32
1 files changed, 32 insertions, 0 deletions
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 <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);
+ }
+}