[英]How to open a new xterm window and run a command on that window using fork-exec calls ? ( C program only)
Basically, I am learning pipe and dup system calls. 基本上,我正在学习管道和重复系统调用。
I want to take a command-name (like ls,cd,mkdir etc) as input from the parent process and pass it on to the child process using pipe, the child process should open up a new xterm window and show the man page of the command recorded in the pipe in this new xterm window. 我想从父进程获取命令名(如ls,cd,mkdir等)作为输入并使用管道将其传递给子进程,子进程应该打开一个新的xterm窗口并显示手册页在新的xterm窗口中记录在管道中的命令。
The problem is that exec changes the whole process image of the child, so any code written after is simply ignored (if exec was successful).So if I exec the child to "/bin/xterm", then any exec calls in the child block are removed, as the process image changed to xterm. 问题是exec改变了孩子的整个过程图像,因此任何编写的代码都会被忽略(如果exec成功)。所以,如果我将孩子执行到“/ bin / xterm”,那么任何exec调用孩子当进程映像更改为xterm时,将删除块。
So how do I call /bin/man? 那么如何调用/ bin / man?
There is nothing stopping you calling fork
again - a process can have any number of children, grandchildren etc... 没有什么可以阻止你再次调用
fork
- 一个进程可以有任意数量的子孙,孙子等......
In this particular instance you need the child to fork
and create grandchildren that exec
"/bin/xterm" with your man command. 在这个特定的实例中,你需要让孩子
fork
并创建使用man命令exec
“/ bin / xterm”的孙子孙女。 And also handle clean up of them as they finish. 并在完成后处理清理工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.