danielinux / ttybus

A simple TTY multiplexer.
GNU General Public License v2.0
114 stars 41 forks source link

Cannot get the right PID from tty_fake #16

Closed leoheck closed 1 year ago

leoheck commented 1 year ago

Hi, I am running this code:

user@pc: $ tty_fake -d -s "/dev/my_tty_mux" "/tmp/my_tty_fake"

user@pc: $ echo "PID=$!, ST=$?"
PID=31163, ST=0

user@pc: $ ps aux | grep tty_fake
main     31429  0.0  0.0   1884    68 ?        Ss   09:12   0:00 tty_fake -o -d -s /dev/my_tty_mux /tmp/my_tty_fake
main     31457  0.0  0.0   7448   572 pts/0    S+   09:14   0:00 grep --color=auto tty_fake

The variable $! is giving me this PID 31163 no matter what I do. But the actual value is different, this time it is 31429. Is there any reason for that? Is there a way to get the right PID straight from the tty_fake command without having to process the ps command, for instance?

danielinux commented 1 year ago

"-d" detaches from the running terminal, so it will fork/fork/setsid/exit. You should perhaps try running without "-d" and putting in background with "&" for use in interactive scripts

leoheck commented 1 year ago

Ah, did not know that the daemon does not generate the $!, thanks for the quick response. Yeah, I agree the & would work.

Since I did not think about that, I am currently using:

pgrep tty_fake -a |  grep ${the_fake_tty} | cut -d" " -f1

which works fine, but it took me some time to figure out that the $! was not working.

Well, I think that's enough for me to close this issue. Thanks @danielinux