Is it possible to terminate a child process without waiting for it to finish using the wait() function? For example, how to complete this child process:

 pid_t pid; switch(pid=fork()) { case 0: for(;;){} default: //здесь код, который завершает дочерний процесс return 0; 

PS If you know some adequate, not very tricky material on fork() where you can learn theoretical knowledge, then send me, pzhl.

    1 answer 1

    Brutal method:

     kill(pid, SIGKILL); 

    Or more gently:

     kill(pid, SIGTERM); 

    In the first case, the child process will simply be killed, in the second it will receive a signal that it can process. But SIGKILL kill the process guaranteed, and in the case of SIGTERM process may refuse to finish the work.

    In the above code, since the process does not seem to contain signal handlers, you can use any method, because, as I pointed out correctly to my @avp error, SIGTERM in the absence of a handler, will also kill the process.

    • Ok, I get it. And about the signal processing can you clarify? What and where should I call to send a signal from the process to the process and process it? - Shadr
    • 2
      If there is no handler, SIGTERM will also terminate the process. Look in the man signal column Action in the section Standard signals (and correct the answer) - avp
    • @avp Thank you. Corrected his mistake. - user194374 1:01 pm
    • one
      @Shadr Look, for example, here: habrahabr.ru/post/141206/ It seems clear described. - user194374