红联Linux门户
Linux帮助

关于终端IO的一点小问题

发布时间:2012-01-05 18:45:35来源:红联作者:princeofdream
现在在学习Terminal IO的一些简单知识,在以下代码中,可以打开关闭对于ctrl + C 产生的信号,然后setattr,问题是,我disable是可以的,然后又enable,对于我编写的程序上,ctrl + C也是没问题,可是中断程序后,回到终端,ctrl+C却不能起作用了,请问怎么理解?谢谢[code]{
struct termios m_term;
long m_vdisable;
long m_get_vable;
char m_ret[2];

if(isatty(STDIN_FILENO)==0)
{
err_sys("Standard input is not a terminal devicd!");
return;
}

if((m_vdisable = fpathconf(STDIN_FILENO,_PC_VDISABLE)) < 0)
{
err_sys("fapthconf error or _POSIX_VDISABLE not in effect!");
return;
}

if(tcgetattr(STDIN_FILENO,&m_term)<0) //fetch tty state
err_sys("tcgetattr error");

if((m_get_vable = m_term.c_cc[VINTR]) != m_vdisable)
{
cout<<"Disable Ctrl + C?"< }
else
{
cout<<"Enable Ctrl + C to interrupt?"< }
cin>>m_ret;
if(strcasecmp(m_ret,"y") == 0)
{
if(m_get_vable != m_vdisable)
m_term.c_cc[VINTR] = m_vdisable; //disable INTR character
else
m_term.c_cc[VINTR] = 3; //enable INTR character to Ctrl + C
}

printf("m_get_vable=%d----m_vdisable=%d\n",m_get_vable,m_vdisable);
// m_term.c_cc[VEOF] = 2; //EOF is Control + B;
// m_term.c_cc[VEOL] = 2; //EOF is Control + B;

if(tcsetattr(STDIN_FILENO,TCSAFLUSH,&m_term)<0)
err_sys("tcsetattr error!");
}[/code]
文章评论

共有 0 条评论