Start a process on a different tty
setsid sh -c 'exec command <> /dev/tty2 >&0 2>&1'
As long as nothing else is using the other TTY (/dev/tty2
in this example), this should work. This includes a getty
process that may be waiting for someone to login; having more than one process reading its input from a TTY will lead to unexpected results.
setsid
takes care of starting the command in a new session.
Note that command
will have to take care of setting the stty
settings correctly, e.g. turn on "cooked mode" and onlcr
so that outputting a newline will add a carriage return, etc.
On the second tty there will be normally a program running, either some login program or some shell like bash. If you want interaction you either would have to replace the login program with yours, or tell a shell to run the program as if the program was started from the commandline.
A more simple solution, IMO, would be to start a tmux
session after logging into the second screen and then use:
tmux send yourcommand ENTER
to start the program in the tmux
session which will display after you switch to the second terminal.
I just made a discovery:
How can I launch applications from 2 ttys on launch?
One of the comments mentions something called openvt
. This command appears to do the exact thing I'm after!
http://linux.about.com/library/cmd/blcmdl1_openvt.htm
Unless anyone knows different, I think this is probably the "correct" way to do this.
(I just tried it, and it seems to work fine - even though getty
is running, it picks the next unused terminal. I guess VTs don't get "opened" until you switch to one to try to log in...)