Warning: Undefined array key "view" in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 47
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 48
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 49
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 50
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 51
/**
* il padre crea un processo figlio e ne attende la terminazione
*/
#include
#include
#include
#include
int main() {
pid_t pid, pid2;
int i, exitstatus;
pid = fork();
if (pid == 0) {
// processo figlio
for (i = 0; i < 10; i++) {
sleep(rand() % 2);
printf("Sono il FIGLIO.\n");
}
exit(11);
}
sleep(rand() % 2);
// processo padre
printf("Sono il processo PADRE e mi metto in attesa...\n");
pid2 = wait(&exitstatus);
printf("Sono il processo PADRE, il figlio [%d] รจ appena terminato con exit status %d e io ho terminato il mio lavoro.\n", pid2, WEXITSTATUS(exitstatus));
exit(0);
}