(02) basic fork
This commit is contained in:
parent
146746ddcf
commit
e0859e823b
1 changed files with 38 additions and 0 deletions
38
02-fork-chimera/main.c
Normal file
38
02-fork-chimera/main.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include <linux/sched.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
const int STACK_SIZE = 4096;
|
||||||
|
|
||||||
|
int child()
|
||||||
|
{
|
||||||
|
printf("Coucou depuis l'enfant\n");
|
||||||
|
printf("parent id: %d\n", getppid());
|
||||||
|
printf("process id: %d\n", getpid());
|
||||||
|
printf("thread id: %d\n", gettid());
|
||||||
|
printf("user id: %d\n", getuid());
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char *stack = (char *) malloc(STACK_SIZE);
|
||||||
|
|
||||||
|
printf("Coucou depuis le parent\n");
|
||||||
|
printf("parent id: %d\n", getppid());
|
||||||
|
printf("process id: %d\n", getpid());
|
||||||
|
printf("thread id: %d\n", gettid());
|
||||||
|
printf("user id: %d\n", getuid());
|
||||||
|
|
||||||
|
/* bizarre la stack ? regarder dans le manuel pourquoi on fait ça, c'est
|
||||||
|
* logique.
|
||||||
|
*/
|
||||||
|
int pid = clone(child, (stack + STACK_SIZE - 1), SIGCHLD);
|
||||||
|
|
||||||
|
free(stack);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue