I wrote a remote tty tool (called "rt"), which works like below:
[rt client(rtc)] <---> [rt gateway(rtg)] <---> [rt server(rts)] where rts is a host behind NAT firewall, it runs rt in /etc/rc.local which connect to rtg. When I want to connec to rts, I run rt on the rtc computer, which connect to rtg, which in turn send the request to rts. The rt program will launch /usr/bin/login in a TTY, thus created a remote terminal between rtc and rts.
My problem is, if I run some command in the remote terminal, then type exit to quit bash, I hope to return to my local terminal prompt, but it almost always hangs with a blank screen, except if I just run some bash command and didn't run any external program in the remote session.
EDIT:
It is a bit hard to precisely define what is external program. I have a feeling that if the program does not "daemonize" then it is considered "internal". i.e. if I run ls, cp, vi etc, it will be fine, but if I run a service program, with & at the end of command line, then rt will hang on exit.
I did some research but is is unfortunately hard to describe the problem in a single sentence. The most relevant resource I can find is:
When terminal emulator exits, why does shell also exits?
I guess it might help if I send SIGHUP somewhere, but how? Which program is the sender and which is the receiver?
nohup?nohupdoes fix my problem. so, how should I proceed, I do not want to use nohup all the time...man 7 signal: "Hangup detected on controlling terminal or death of controlling process"