I'm trying to do a program that makes activate an signal (SINGALARM) when the next child of a son appears but this not works.
I have to caught the next child o the other (pid), to send a singnal which inform a menssage.
It's anything worng in the code?
thanks.
the code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
void sigalrm_handler(int);
static void sig_usr(int);
int orden=0;
pid_t padre,hijo,pid,pidPadre,PIDSIG;
int main(int argc, char **argv)
{
pid_t padre,hijo,pid,pidPadre;
padre=getpid();
pid=getpid();
int i=0;
FILE *arch;//Archivo a verificar.
signal(SIGALRM,sigalrm_handler);
for(i=0;i<10;i++)
{
if((hijo=fork())==0)
{
pidPadre=getppid();
pid=getpid();
orden=i+1;
printf("\nN�%d Pid:%d PPid:%d\n",orden,pid,pidPadre);
}
else
{
PIDSIG=hijo;
break;
}
}
char cadena[100];
for(; ;)
{
sprintf(cadena,"%d",orden);
if((arch=fopen(cadena,"r"))==NULL)
{
printf("\nno existe\n");
}
else
{
pid=getpid();
printf("\nN�%d Pid:%d Archivo Existente\n",orden,pid);
sleep(1);
}
sleep(3);
if ( pid == PIDSIG )
alarm( 5 );
}
}
static void sig_usr(int signo)
{
return;
}
void sigalrm_handler(int senial)
{
printf("\nN�%d Pid:%d Archivo Existente SE�ALIDADO X+1 \n",orden,pid);
alarm( 5 );
}