告诉伪终端的从端口名称

时间:2022-07-05 21:06:08

I am coding a linux process that will read input from a serial stream (a GPS module) and perform some actions based on this input.

我正在编写一个linux进程,它将从串行流(GPS模块)读取输入,并根据此输入执行一些操作。

When developing the program I intend to use a Pseudo Terminal (BSD API) so I can send 'dummy' GPS ascii data to my process and test it. So my master will be my 'GPS Device' and my slave will be my actual linux process that handles the GPS data.

在开发程序时,我打算使用伪终端(BSD API),这样我就可以将“虚拟”GPS ascii数据发送到我的进程并进行测试。所以我的主人将是我的'GPS设备',我的奴隶将是我处理GPS数据的实际linux进程。

I don't want to fork my process but have 2 different programs (the master and the slave). This way I can separate the code nicely. How can I tell me slave what port name to connect to? Ie; /dev/ttp0 or etc?

我不想分叉我的进程但有2个不同的程序(主和从)。这样我就可以很好地分离代码。如何告诉我slave要连接的端口名称?即; / dev / ttp0等等?

Maybe I am using Pseudo Terminal's wrong and should fork them?

也许我正在使用Pseudo Terminal的错误并应该分叉它们?

2 个解决方案

#1


ways to pass info (the port number) between processes.

在进程之间传递信息(端口号)的方法。

1) use msgsnd()
2) use a pipe()
3) use a mmap area

there are several other methods. I prefer the msgsnd

还有其他几种方法。我更喜欢msgsnd

#2


4) Link to it with a soft link with a fixed name.

4)使用具有固定名称的软链接链接到它。

For example: /tmp/gpsdevice -> /dev/pts/2. This is trivial to do in the master with symlink.

例如:/ tmp / gpsdevice - > / dev / pts / 2。使用符号链接在master中这很简单。

#1


ways to pass info (the port number) between processes.

在进程之间传递信息(端口号)的方法。

1) use msgsnd()
2) use a pipe()
3) use a mmap area

there are several other methods. I prefer the msgsnd

还有其他几种方法。我更喜欢msgsnd

#2


4) Link to it with a soft link with a fixed name.

4)使用具有固定名称的软链接链接到它。

For example: /tmp/gpsdevice -> /dev/pts/2. This is trivial to do in the master with symlink.

例如:/ tmp / gpsdevice - > / dev / pts / 2。使用符号链接在master中这很简单。