Linux best practice to run and view another process

In my process, I need to start / restart another process. I am currently using a stream with a small stack size and the following code:

void startAndMonitorA()
{
  while(true)
  {
    system("myProcess");
    LOG("myProcess crashed");
    usleep(1000 * 1000);
  }
}

I feel that this is not the best practice. I have no idea about the resources that the call is std::system()blocking or wasting. I am in embedded Linux - so in general I try to take care of resources.

+4
source share
2 answers

, , . , , ( ) , . , ( ).

:

  • system() fork() exec(), . PID .
  • SIGCHLD, , . , .
  • , waitpid WNOHANG , , . waitpid() PID , , , PID -, .
0

: , 100% . (, ). , .


system Linux:

  • SIGINT SIGQUIT .
  • SIGCHLD.
  • fork()
  • exec(), .
  • waitpid(), .
  • .

system, , , 5 ( 1, 2 6), SIGCHLD, , .

, SIGCHLD fork exec.

+3

Source: https://habr.com/ru/post/1670927/


All Articles