シリアルポート/ dev/ttyUSB0(FTDIを使用)のデバイスを使用しています。ファイルディスクリプタを他の生成されたプロセスにリークさせたくないので、close-on-execフラグをディスクリプタ。あなたは、開口部ながらO_CLOEXECを設定することの違いは何を教えてもらえ:O_CLOEXECとTIOCEXCLの違い
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
int fd, rc;
fd = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_CLOEXEC);
if(fd < 0)
{
perror("error open:");
exit(-1);
}
rc = close(fd);
if(rc != 0)
{
perror("error close:");
exit(-1);
}
return 0;
}
とのioctl(FD、TIOCEXCL)とクローズ(close-on-exec)設定:
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
int fd, rc;
fd = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY);
if(fd < 0)
{
perror("error open:");
exit(-1);
}
rc = ioctl(fd, TIOCEXCL);
if(rc != 0)
{
perror("error ioctl:");
exit(-1);
}
rc = close(fd);
if(rc != 0)
{
perror("error close:");
exit(-1);
}
return 0;
}
'TIOCEXCL'は" exec on close "ではありません。端末を「排他的」モードにする。ファイル記述子の漏洩を防ぐこととは何の関係もありません。代わりに 'fcntl(fd、F_SETFD、old_flags | FD_CLOEXEC)'を考えているかもしれません。 –