#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <signal.h>
//----------------------------------------------------------
void signal_handler (int signal)
{
int status;
pid_t pid;
if (signal == SIGCHLD)
{
pid = wait (&status);
printf ("Il processo %i si è concluso restituendo " "il valore %x.\n",
pid, WEXITSTATUS (status));
}
}
//----------------------------------------------------------
int
main (void)
{
pid_t pid;
//
signal (SIGCHLD, signal_handler);
//
pid = fork ();
if (pid == 0)
{
sleep (1);
}
printf ("Ho avviato il processo %i.\n", pid
); //
sleep (60);
//
return (0);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx1bmlzdGQuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3lzL3dhaXQuaD4KI2luY2x1ZGUgPHNpZ25hbC5oPgovLy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0Kdm9pZCBzaWduYWxfaGFuZGxlciAoaW50IHNpZ25hbCkKewogICAgaW50ICAgc3RhdHVzOwogICAgcGlkX3QgcGlkOwogICAgaWYgKHNpZ25hbCA9PSBTSUdDSExEKQogICAgICB7CiAgICAgICAgcGlkID0gd2FpdCAoJnN0YXR1cyk7CiAgICAgICAgcHJpbnRmICgiSWwgcHJvY2Vzc28gJWkgc2kgw6ggY29uY2x1c28gcmVzdGl0dWVuZG8gIgogICAgICAgICAgICAgICAgImlsIHZhbG9yZSAleC5cbiIsCiAgICAgICAgICAgICAgICBwaWQsIFdFWElUU1RBVFVTIChzdGF0dXMpKTsKICAgICAgfQp9Ci8vLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQppbnQKbWFpbiAodm9pZCkKewogICAgcGlkX3QgIHBpZDsKICAgIC8vCiAgICBzaWduYWwgKFNJR0NITEQsIHNpZ25hbF9oYW5kbGVyKTsKICAgI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