cominglately 2015-11-15 03:40 采纳率: 72.1%
浏览 771

linux 环境,tcgetsid(STDOUT_FILENO),返回error

linux 环境,tcgetsid(STDOUT_FILENO),返回error: Inappropriate ioctl for device
 实验,检测会话是否存在:    
        getsid(0),替换
       返回SID=29307
实验说明会话存在,那么tcgetsid( argumen 【?】),argument应该怎么填写呢?

    源码:

#include"apue.h"
int main()
{
pid_t pid;
if((pid=fork()) err_sys("fork error");
else if(pid!=0)
exit(0);
else
{
printf("waitting for parent leaving\n");
sleep(5);
pid_t pid,pgid,pid4,pid3,sid;
if((sid=setsid())==-1)
err_sys("sersid error");
pid=getpid();
pgid=getpgrp();
if(pid==pgid)
printf("The current process becomes the process group id :%ld\n",(long)pid);
if((sid=tcgetsid(STDIN_FILENO))==-1)
{
printf("EBADF=%d\t,ENOTTY=%d\n",EBADF,ENOTTY);
printf("errno:%d\n",errno);
err_sys("tcgetsid error");
}
/*#include
pid_t tcgetsid(int fd);
*return the session ID ,only when fd refers to the controlling terminal of our session.Otherwise -1 is returned,and errno is set appropriately.
/
printf("SID=%ld\n",(long)sid);
}
exit(0);
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配