prueba
#include
#include
#include
#include
#define M 3.0 // Duración de la tarea del proceso padre
#define N 5.0 // Duración de la tarea del proceso padre
void funcion(int sig);
int main(void) {
int x, i = 0;
pid_t pid;
pid = fork(); // Creamos un hijo
// Creamos aqui la variable ss para que padre he hijo la tengan
struct sigaction ss;
ss.sa_handler =funcion;
// Enmascaramos la senal SIGUSR1 para padre e hijo
if (-1 == sigaction(SIGUSR1, &ss, NULL)) {
perror("ERROR: sigaction (SIGUSR1)");
return 1;
}
if(pid == -1) {
perror("Error en la llamada a fork()");
exit(0);
} else if(pid == 0) {
while(1) {
pause();
srand (getpid());
x = 1 + (int)(N * rand() / RAND_MAX + 1.0);
/* x es un número aleatorio entre 1 yN */
printf("COMIENZO TAREA HIJO %d\n", i);
sleep(x);
printf("FIN TAREA HIJO %d\n", i);
i++;
kill(getppid(), SIGUSR1);
}
} else {
while(1) {
srand (getpid());
x = 1 + (int)(M * rand() / RAND_MAX + 1.0);
/* x es un número aleatorio entre 1 y N */
printf("COMIENZO TAREA PADRE %d\n", i);
sleep(x);
printf("FIN TAREA PADRE %d\n", i);i++;
kill(pid, SIGUSR1);
pause();
}
}
return 0;
}
void funcion(int sig) {
// Imprimimos por pantalla unicamente "Manejadora" en cada llamada
printf("Manejadora\n");
}#include
#include
#include
#include
#include
#define M 3.0 // Duración de la tarea del proceso padre
#define N 5.0 // Duración de la tarea del proceso padre
void funcion(int sig);
intmain(void) {
int x, i = 0;
pid_t pid;
pid = fork(); // Creamos un hijo
// Creamos aqui la variable ss para que padre he hijo la tengan
struct sigaction ss;
ss.sa_handler = funcion;
// Enmascaramos la senal SIGUSR1 para padre e hijo
if (-1 == sigaction(SIGUSR1, &ss, NULL)) {
perror("ERROR: sigaction (SIGUSR1)");
return 1;
}
if(pid == -1) {
perror("Error en lallamada a fork()");
exit(0);
} else if(pid == 0) {
while(1) {
pause();
srand (getpid());
x = 1 + (int)(N * rand() / RAND_MAX + 1.0);
/* x es un número aleatorio entre 1 y N */
printf("COMIENZO TAREA HIJO %d\n", i);
sleep(x);
printf("FIN TAREA HIJO %d\n", i);
i++;
kill(getppid(), SIGUSR1);
}
} else {
while(1) {
srand (getpid());
x= 1 + (int)(M * rand() / RAND_MAX + 1.0);
/* x es un número aleatorio entre 1 y N */
printf("COMIENZO TAREA PADRE %d\n", i);
sleep(x);
printf("FIN TAREA PADRE %d\n", i);
i++;
kill(pid, SIGUSR1);
pause();
}
}
return 0;
}
void funcion(int sig) {
// Imprimimos por pantalla unicamente "Manejadora" en cada llamada
printf("Manejadora\n");}#include
#include
#include
#include
#include
#define M 3.0 // Duración de la tarea del proceso padre
#define N 5.0 // Duración de la tarea del proceso padre
void funcion(int sig);
int main(void) {
int x, i = 0;
pid_t pid;
pid = fork(); // Creamos un hijo
// Creamos aqui la variable ss para que padre he hijo la tengan
struct sigaction ss;
ss.sa_handler = funcion;// Enmascaramos la senal SIGUSR1 para padre e hijo
if (-1 == sigaction(SIGUSR1, &ss, NULL)) {
perror("ERROR: sigaction (SIGUSR1)");
return 1;
}
if(pid == -1) {
perror("Error en la llamada a fork()");
exit(0);
} else if(pid == 0) {
while(1) {
pause();
srand (getpid());
x = 1 + (int)(N * rand() / RAND_MAX + 1.0);
/* x es un número aleatorio entre 1 y N */printf("COMIENZO TAREA HIJO %d\n", i);
sleep(x);
printf("FIN TAREA HIJO %d\n", i);
i++;
kill(getppid(), SIGUSR1);
}
} else {
while(1) {
srand (getpid());
x = 1 + (int)(M * rand() / RAND_MAX + 1.0);
/* x es un número aleatorio entre 1 y N */
printf("COMIENZO TAREA PADRE %d\n", i);
sleep(x);
printf("FIN TAREA PADRE %d\n", i);
i++;...
Regístrate para leer el documento completo.