Linux:how to 'fork' not exec a new process

2019-09-15 01:57发布

问题:

i am using fedora 15 with posix, and i want to fork my child processes in a new terminal window where i can interact only with the child process while the parent remain int he original terminal. I do not want to exec because that would require me to re arrange all of my code which doesnt seem fesaible at this moment as i have to present my project day after tomorrow.is it possible?how? i have tried forkpty but it gives me a compilation error.

回答1:

Have a look to man screen. I think it can be what you're looking for..

For example, you can run:

screen -dmS SESSION_NAME bash -c "COMMAND"

Where SESSION_NAME name is the name of the session, and COMMAND the command that you want to execute. In this way it will start as daemon, detached from your current shell. You're not obliged to do it, but it seems the solution that better fit your question. Remove -dmS SESSION_NAME if you want it in foreground.

Then, you can interact with the child with:

screen -r SESSION_NAME

You can come back to the main shell with:

screen -d