Documente Academic
Documente Profesional
Documente Cultură
/***********************************************************************\
exemple_fork
\***********************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
int main (void)
{
pid_t pid_fils;
do {
pid_fils = fork();
} while ((pid_fils == -1) && (errno == EAGAIN));
if (pid_fils == -1) {
fprintf(stderr, "fork() impossible, errno=%d\n", errno);
return 1;
}
if (pid_fils == 0) {
/* processus fils */
1
Exercice 2
Soit le programme suivant:
#include <stdio.h>
main()
{
int pid;
pid = fork();
if (pid == 0)
{
// for(;;)
printf ("je suis le fils\n");
}
else
{
// for(;;)
printf("je suis le pre\n");
}
}
1.
2.
3.
4.
5.
6.
7.
Exercice n3
1.
2.
3.
4.
i = i + 20;
printf ("hello, fils %d\n", i);
}
else
{
i = i + 1000;
printf ("hello, pre %d\n", i);
i = i + 2000;
printf ("hello, pre %d\n", i);
wait();
}
}