0
我使用“信号”功能有一些其他麻烦。我有5个子进程和它的父亲。信号错误:“无效使用void表达式”
一次只能运行一个进程,并且该进程应该有一些延迟(从1到10秒)变为另一个偶然进程。对于这些更改,它必须使用SIGUSER1信号。这是我的代码,我有错误:
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()));
}
据我所知,“manejador”可以具有一个int值 无效manejador(int类型){printf的 (用来调用的函数”接收到的信号%d \ n“,s); }
但是我需要2个变量,因为我应该停止当前进程并重新启动新进程。
我有确切的错误说:
error: invalid use of void expression
能否请你帮我?
如果我只是把“manejador”我得到这样的警告:警告:SI的传递参数2不兼容的指针类型[缺省情况下启用]。 /usr/include/signal.h:101:23:note:expected'__sighandler_t'but argument is of type'void(*)(int,int)' – user1660559