syscall_avent/02-fork-chimera/main.c

39 lines
842 B
C
Raw Normal View History

2022-12-08 17:31:20 +01:00
#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;
}