Getting unwanted signals/input from terminal in c program

83 views Asked by At

I written c program in the below concepts.

main_process.c

   /* check the give process id is alive or not. if not alive then start that process.*/
   void * thread1()
   {
     while(1) {
       if (kill(pid, 0)!=0) {
         system(process1);
       }
     }
   }

  /* Get the process id for the started process */
   void *thread2() {
     while (1) {
       FILE *fp = popen("ps -af | grep "process1");
       get_pid(pid, fp);
       pclose(pid);
     }
   }

   get_pid(pid, fp) {
     /*  Get the pid for the new process using getline() and string parsing using string token function, its long code so not pasted here.*/
   }

   main(int arg, char *args[]) {
     pthread_t tid1, tid2;
     pthread_create(tid1,NULL, &thread1, NULL);
     pthread_create(tid2, NULL, &thread2, NULL);
     //Checks thread created success or not.
     pthread_join(tid1);
     pthread_join(tid2);
   }

process:

   main() {
     char input[100];
     while (1) {
       fgets(input, 100, stdin);
       printf("\n Input is %s \n", input);
     }

I started the process program first, and get the pid and starting the main_process. After some time I killed the process program using kill -9 pid. So the if condition of thread1 in main_process passed and starts the process program.

Getting inputs from the terminal. After some time I again killed the process program using kill -9 pid. So thread1 again starts the process program.

Issue is the following: When the process program starts for the second time, getting unwanted inputs from terminal. I have no idea about who's sending, issue in keyboard or in my program concepts.

Please inform where I made mistakes.

0

There are 0 answers