首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能在windows中使用tcgetpgrp()?

不能在windows中使用tcgetpgrp()?
EN

Stack Overflow用户
提问于 2013-08-03 17:19:29
回答 1查看 206关注 0票数 1

我正在尝试用C在windows中构建一个简单的shell,我的平台不好,所以我搜索并开始了一些代码,如下所示:

代码语言:javascript
复制
shell_terminal = STDIN_FILENO;
shell_is_interactive = isatty (shell_terminal);
if (shell_is_interactive)
{
    /* Loop until we are in the foreground.  */
    while (tcgetpgrp (shell_terminal) != (shell_pgid = getpgrp ()))
    kill (- shell_pgid, SIGTTIN);

    /* Ignore interactive and job-control signals.  */
    signal (SIGINT, SIG_IGN);
    signal (SIGQUIT, SIG_IGN);
    signal (SIGTSTP, SIG_IGN);
    signal (SIGTTIN, SIG_IGN);
    signal (SIGTTOU, SIG_IGN);
    signal (SIGCHLD, SIG_IGN);

    /* Put ourselves in our own process group.  */
    shell_pgid = getpid ();
    if (setpgid (shell_pgid, shell_pgid) < 0)
    {
    perror ("Couldn't put the shell in its own process group");
    exit (1);
    }

    /* Grab control of the terminal.  */
    tcsetpgrp (shell_terminal, shell_pgid);

    /* Save default terminal attributes for shell.  */
    tcgetattr (shell_terminal, &shell_tmodes);
}

但是我有一些bug:

代码语言:javascript
复制
[Error] 'tcgetpgrp' was not declared in this scope
[Error] 'getpgrp' was not declared in this scope
[Error] 'SIGTTIN' was not declared in this scope
[Error] 'kill' was not declared in this scope
...

我想我的环境有问题,或者错过了一些库。我有什么问题?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2013-08-03 17:32:33

因为,tcgetpgrp函数不是由所有操作系统都必须支持的ISO C standard定义的,而是由Unix系统环境最常支持的IEEE POSIX标准定义的。

例如:

编译此程序所需的<unistd.h>是由POSIX标准定义的头文件,而不是ISO C标准定义的头文件。

要么升级到POSIX兼容系统,要么使用为windows平台提供类似服务Windows API

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18031289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档