The father forks as many children as the parameter given from the command line.The children after birth are paused and the father awakens them by sending signal. However, in the way I wrote it the children never seem to get the awaking signal. Do I get the concept of children pids wrong and that's why they never get the signal?
./test 4 5 1 3 2
as posted above 4, 5, .... stand for child 4, child 5, ... I save them consecutively as they are posted from the command line in array for saving their indexes (for later usage...) and their pids in another array . I want to send the signal (the father wants) consecutively as cited in the command line
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<signal.h>
void handler();
int main(int argc, char **argv){
pid_t proc_pid[argc-1], order[argc-1];
int i;
for(i=0;i<=argc-2;i++){
order[i]=atoi(argv[i+1]);
//printf("%d\n",order[i]);
//printf("%d\n",i);
if((proc_pid[i] = fork()) < 0){
perror("fork");
}
else if(proc_pid[i] == 0){
// proc_pid[i]=getpid();
printf("%d\n",proc_pid[i]);
pause();
signal(SIGINT, handler);
exit(0);
}
else{
kill(proc_pid[i], SIGINT);
//kill(0, SIGINT);
// exit(0);
}
}
return 0;
}
void handler(){
printf("ok\n");
}