Better name for examples dir
[lcapit-junk-code.git] / snippets / C / clone.c
blobc37733f528136b939d88b041b74f46045c99b915
1 /*
2 * Linux's clone() system call usage example
3 */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <sched.h>
7 #include <sys/wait.h>
8 #include <sys/types.h>
10 #define UNUSED(x) (x = x)
11 #define STACK_SIZE 16
13 int child(void *arg)
15 UNUSED(arg);
17 printf("[child] Hello world!\n");
18 return 0;
21 int main(void)
23 int tid;
24 char stack[STACK_SIZE];
26 tid = clone(child, (void *) stack, 0, NULL);
27 if (tid < 0) {
28 perror("clone()");
29 exit(1);
32 wait(NULL);
34 printf("[parent]: exiting\n");
35 return 0;