Linux:如何“分叉"不在新的终端窗口中执行新过程? [英] Linux:how to 'fork' not exec a new process in a new terminal window?

查看:71
本文介绍了Linux:如何“分叉"不在新的终端窗口中执行新过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将fedora 15与posix一起使用,并且我想在新的终端窗口中派生我的子进程,在该窗口中,我只能与子进程进行交互,而父进程仍保留在原始终端中.我不想执行,因为这将要求我重新排列所有当前似乎不可行的代码,因为我必须在第二天以后提交项目.这可能吗?怎么办? 我已经尝试过forkpty,但这给了我一个编译错误.

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.

推荐答案

看看man screen.我想这可能就是您要寻找的东西.

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

例如,您可以运行:

screen -dmS SESSION_NAME bash -c "COMMAND"

其中SESSION_NAME name是会话的名称,而COMMAND您要执行的命令.这样,它将作为守护程序启动,与您当前的shell分离.您没有义务这样做,但是看来解决方案更适合您的问题.如果要在前景中删除-dmS SESSION_NAME,则将其删除.

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

这篇关于Linux:如何“分叉"不在新的终端窗口中执行新过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆