linux tty结束进程,linux - 为什么杀死配置了Linux tty的进程后open()会挂起? - 堆栈内存溢出...

我想将Linux的串行端口设置为115200波特的“原始”模式。 如果我运行以下程序

#include

#include

#include

#include

#include

#include

#include

int main(int argc, char **argv)

{

int fd= open( "/dev/ttyS0", O_RDWR );

if ( fd < 0 )

{

perror(0);

int err = errno;

fprintf( stderr, "can't open /dev/ttyS0 got err %d\n",err );

return err;

}

printf("got fd %d\n", fd );

struct termios old;

tcgetattr(fd,&old);

struct termios news;

// enable raw comms

cfmakeraw( &news);

// set port to 115200 baud

cfsetispeed(&news, B115200);

tcsetattr( fd, TCSANOW,&news);

printf("set raw 115200\n");

usleep(5000000);

printf( "slept\n");

tcsetattr( fd, TCSANOW,&old);

printf( "restored\n");

close(fd);

printf("closed\n");

}

并在Ctrl-C睡眠期间中断它,然后再次运行它,第二次没有输出-程序在open()调用期间挂起。 即使以root身份运行也无济于事。

没有迹象表明第一个进程仍在使用该端口或该端口已被锁定,在/ var / lock /或ps aux |中没有明显的迹象。 grep tty

现在,我最好的选择是确保每当使用tty的进程终止时,它都会正确关闭端口。 但是,为什么这个问题会出现呢? 中止的进程不应该释放端口吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值