I have some other trouble using the "signal" function. I have 5 children processes and its father.
Only one process should be running at a time, and that process should change to another aleatory process with some delay (from 1 to 10 seconds). For those changes its mandatory to use SIGUSER1 signal. This is my code and the error I'm having:
struct compartido{
int pid1, pid2, pid3, pid4, pid5;
int propietario;
int contador;
int pidpadre;
};
struct compartido* var;
void manejador(int prop, int actual){
if(signal(SIGUSR1,SIG_IGN)==SIG_ERR){
perror("Error en el Signal.\n");
exit(2);
}
printf("Proceso %d al mando en el manejador.\n",prop);
kill(prop,SIGCONT);
if(actual==getpid()) kill(actual,SIGSTOP);
sleep(rand() % 11 + 1);
}
int main(int argc, char *argv[]) {
key_t llave1,llavesem;
int idmem,idsem;
idmem=shmget(llave1,sizeof(struct compartido),IPC_CREAT|0600);
if (idmem==-1) {
perror ("shmget");
return 1;
}
var=(struct compartido*) shmat(idmem,0,0);
var->pidpadre=getpid();
var->propietario=var->pid1;
/*Next line gives the error*/
if(var->pid1==getpid()) signal(SIGUSR1,manejador(var->propietario, getpid()));
/*Doing more things inside...*/
/*Next line gives the error*/
signal(SIGUSR1,manejador(var->propietario, getpid()));
}
As far as I know, the function called "manejador" could be used with one int value void manejador(int s){ printf("Signal received %d\n",s); }
But I need 2 variables inside, because I should stop the current process and relaunch the new one.
The exact error I'm having says:
error: invalid use of void expression
Can you please, help me?