c - Unable to kill processes running concurrently -


i running program a.c concurrently, 5 times. part of code given below:

int main(int argc, char *argv[]){      char s = 0;     int = 0;     pid_t procb_id = 0;     int retval = 0;      struct sigaction act;     ch = &c[0];     memset(c, 0, 50);      // open file entered in command-line reading      fptr = fopen(argv[1], "r");      if(fptr == null){             printf("error - input file not opened reading!\n");         exit(exit_failure);         }      // write characters read file pointer array     while((s=fgetc(fptr)) != eof){         ch[i] = s;         i++;     }     printf("length of text: %d\n",i);      sigemptyset(&act.sa_mask);     act.sa_flags = sa_siginfo;     act.sa_sigaction = handlera;      if((sigaction(sigrtmin, &act, null)) != 0){         printf("signal not registered!\n");         }      //get pid of daemon b able send real-time signal, indicating has started     procb_id = getbprocessid();      printf("process id of b: %d\n", (int) procb_id);      //call sendsignal() method send real-time signal b     retval = sendbsignal(procb_id);      if(retval == 1){          while(n < 0){             //printf("before pause\n");             pause();         }         //writetofifo(n);         if(writetofifo(n) == 1){             n = -1;             exit(exit_success);         }     }       while (1); } 

the relevant part of code exit(exit_success). however, when running process in parallel, 1 process exiting, not rest. others still running. running process in parallel following shell script:

for ((i=1;i<=5;i++))       ./a file.txt & done 

"file.txt" file each process has read separately. want kill 5 processes, not one. know how can that? please help. guess code not correct, don't know here.

i want kill 5 processes, not one. know how can that?

pkill -f "a file.txt" 

you lost do loop infinite while(1):

do {     procb_id = getbprocessid();      printf("process id of b: %d\n", (int) procb_id);      //call sendsignal() method send real-time signal b     retval = sendbsignal(procb_id);      if(retval == 1){         while(n < 0){             //printf("before pause\n");             pause();         }         //writetofifo(n);         if(writetofifo(n) == 1){             n = -1;             exit(exit_success);         }     } } while (1); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -