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);
}