c - 为什么串口要设置 'no terminal should control the process'选项?

标签 c linux terminal serial-port

fd = open("/dev/ttyUSB0",O_RDWR | O_NOCTTY);    
                               /* O_NOCTTY - No terminal will control the process   */

为什么要指定或不指定这个选项?它做什么和不做什么?

最佳答案

这在 GNU C library 的文档中得到了回答。 :

If the named file is a terminal device, don’t make it the controlling terminal for the process. See Job Control, for information about what it means to be the controlling terminal.

On GNU/Hurd systems and 4.4 BSD, opening a file never makes it the controlling terminal and O_NOCTTY is zero. However, GNU/Linux systems and some other systems use a nonzero value for O_NOCTTY and set the controlling terminal when you open a file that is a terminal device; so to be portable, use O_NOCTTY when it is important to avoid this.

也就是说,由于 USB 串行设备被视为终端,使用标志是您不希望它终端并允许设备启动/停止恰好与给定用户连接的作业(例如,进程)。

进一步阅读:

关于c - 为什么串口要设置 'no terminal should control the process'选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54360113/

相关文章:

xcode - 终端中的 "./"和 "open"有什么区别,如何从 XCode 运行 Unix 可执行文件?

c - 为什么这个 Shaker Sort 代码在 C 中不起作用

linux中的C用户名——获取当前用户名

c - 递归扫描文件夹树C

linux - 在 bash 文件中运行多个查找和 sed

linux - Linux 终端中的 For 循环

regex - 在linux中使用正则表达式重命名文件

c++ - 从 c 调用 swift

c++ - 在没有atm开关的情况下模拟atm通信

ruby-on-rails - 如何对使用 rails Logger.new 创建或轮换的文件设置 664(或自定义)权限?