repo.or.cz
/
lcapit-junk-code.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Introduce old redir program
[lcapit-junk-code.git]
/
snippets
/
C
/
clone.c
blob
c37733f528136b939d88b041b74f46045c99b915
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>
9
10
#define UNUSED(x) (x = x)
11
#define STACK_SIZE 16
12
13
int
child
(
void
*
arg
)
14
{
15
UNUSED
(
arg
);
16
17
printf
(
"[child] Hello world!
\n
"
);
18
return
0
;
19
}
20
21
int
main
(
void
)
22
{
23
int
tid
;
24
char
stack
[
STACK_SIZE
];
25
26
tid
=
clone
(
child
, (
void
*)
stack
,
0
,
NULL
);
27
if
(
tid
<
0
) {
28
perror
(
"clone()"
);
29
exit
(
1
);
30
}
31
32
wait
(
NULL
);
33
34
printf
(
"[parent]: exiting
\n
"
);
35
return
0
;
36
}