39 lines
842 B
C
39 lines
842 B
C
|
#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;
|
||
|
}
|