How can a C/C++ program put itself into background?

前端 未结 20 1765
难免孤独
难免孤独 2020-12-09 18:16

What\'s the best way for a running C or C++ program that\'s been launched from the command line to put itself into the background, equivalent to if the user had launched fro

20条回答
  •  青春惊慌失措
    2020-12-09 18:45

    I was trying the solution.

    Only one fork is needed from the parent process.

    The most important point is that, after fork, the parent process must die by calling _exit(0); and NOT by calling exit(0);

    When _exit(0); is used, the command prompt immediately returns on the shell.

    This is the trick.

提交回复
热议问题