我如何获得tcsetpgrp(c)中工作? [英] How do I get tcsetpgrp() to work in C?

查看:234
本文介绍了我如何获得tcsetpgrp(c)中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给一个子进程(通过叉())的前景接入终端。

I'm trying to give a child process (via fork()) foreground access to the terminal.

在我叉(),我运行子进程以下code:

After I fork(), I run the following code in the child process:

setpgid(0, 0);

setpgid(child, child);

在父进程。

这给孩子自身的进程组。到 setpgid()正常工作的电话。

This gives the child its own process group. The call to setpgid() works correctly.

现在我想给孩子访问终端。

Now I want to give the child access to the terminal.

我添加了以下到 setpgid()调用后孩子:

I added the following to the child after the setpgid() call:

if (!tcsetpgrp(STDIN_FILENO, getpid())) {
    perror("tcsetpgrp failed");
}

在此之后,有一个 execv()命令产卵的/ usr / bin中/纳米

不过,而不必纳米上来,没有任何反应,并且终端看起来好像它希望用户输入。

However, instead of having nano come up, nothing happens, and the terminal looks as if it's expecting user input.

此外,没有code似乎 tcsetpgrp后执行()电话。

Further, no code seems to execute after the tcsetpgrp() call.

我读的地方,我需要一个 SIGCONT 信号发送到子进程来得到它的工作。如果进程停止,我该怎么办呢?是否有家长发送信号?

I read somewhere that I need to send a SIGCONT signal to the child process to get it to work. If the process is stopped, how can I do that? Does the parent have to send the signal?

我如何去发送 SIGCONT 信号如果解决?

How do I go about sending the SIGCONT signal if that is the solution?

raise(SIGCONT);

此外,我不知道这会有所帮助,但code正常工作和产卵纳米如果我运行我的程序有:

Also, I'm not sure if this helps, but the code works fine and spawns nano if I run my program with:

exec ./program

而不是:

./program

任何想法?非常感谢!

Any ideas? Thanks so much!

推荐答案

3人状态tcsetpgrp:

man 3 tcsetpgrp states:

如果tcsetpgrp()是在其会话中的后台进程组的成员调用,调用进程不会阻止或忽略SIGTTOU,一个SIGTTOU信号发送到该后台进程组的所有成员。

If tcsetpgrp() is called by a member of a background process group in its session, and the calling process is not blocking or ignoring SIGTTOU, a SIGTTOU signal is sent to all members of this background process group.

您需要调用tcsetpgrp()在你的父进程没有孩子。但是,如果你的父进程开始搬进背景它将接收和SIGTTOU将被停止。

You need to call tcsetpgrp() in your parent process not in child. However if your parent process started and moved into background it will receive SIGTTOU and will be stopped.

这篇关于我如何获得tcsetpgrp(c)中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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