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

前端 未结 20 1763
难免孤独
难免孤独 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 19:04

    To followup on your edited question:

    I was wondering if there was a way to put the EXISTING process into the background.

    In a Unix-like OS, there really is not a way to do this that I know of. The shell is blocked because it is executing one of the variants of a wait() call, waiting for the child process to exit. There is not a way for the child process to remain running but somehow cause the shell's wait() to return with a "please stop watching me" status. The reason you have the child fork and exit the original is so the shell will return from wait().

提交回复
热议问题