Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On my office computer (running Scientific Linux 6.3) I have several windows running some processes in separate terminal emulators (/dev/pts/). I often connect to my office computer with iSSH from my iPad, but I can only see the results of the programs that have been written to a file and can't see what each terminal is showing or control the terminals.

I want to be able to temporarily switch control of a terminal to my iPad iSSH terminal, look at the results, run new commands (on my office terminal from my iPad) then let the program run on my office computer and return back to my iSSH terminal, so I can check other terminals or simply quit. Since I use 3G most of the time to connect with my iPad I don't want to use any graphically depenent method which will be very slow.

As far as I have understood, something like reptyr seems to permanently move control of a process from one terminal to another, I haven't seen any one talk (or ask) about giving control back to the original terminal. I want to return it back to it's original terminal after I finish.

I would really appreciate any suggestions or help. Thanks in advance

share|improve this question

1 Answer 1

up vote 8 down vote accepted

I believe you need just to run the original commands inside a screen session.

Then you can disconnect from it (screen keeps on runnign and keep your "virtual terminal" displayed correctly), and re-attach to it from another session (ie, from your ipad, or from another computer, or from the same computer when you get back to it).

There are many more things screen can do too (such as, for example, allow a co-worker to "sneak" to your running screen session as you use it, or when you are away from it, allowing to have several persons peeking at the same "terminal")

in a nutshell:

on your primary terminal, on host A, as user ORIGINALUSER:

screen
command (ex: vi /tmp/file)
CTRL+a d # which is 'CTRL' and 'a' at the same time, and then 'd'. This will 'd'etach from the screen session, while screen itself still runs! (and inside it the commands, shell and any still running invoked command, still run)

on another terminal (or the same one) :

#log in the original machine (host A) as the same user ORIGINALUSER, and then:
screen -r   #will reattach to the latest running screen from that user. 

If there is more than one screen to reattach to, see the screen man page or on the net. (usefull too if you can't reattach : there are ways to "force" it to reattach)

Once really finished : you just exit the shell running inside the screen. This will terminate the screen command too.

while in screen: ctrl+A is special, and allows to send commands to screen. Try : ctrl+A ?

share|improve this answer
    
Thank you very much Olivier for your very complete reply. I will try the method at work tomorrow and write the result here. I am new to Linux and really excited at all the possibilites. –  makhlaghi Dec 26 '12 at 16:52
    
@astroboy I'd recommend you to look at tmux also, it is like screen, but may be more comfortable for you to use (though it's a matter of taste). –  EarlGray Dec 26 '12 at 22:29
    
I tried it out and it works great, thanks. I just had one more question. The processes that are running in the terminals are very CPU intensive. In fact that is the reason I separate them into different terminals to use as much of the CPU cores as possible. When I wrap all the processes into one process (screen or tmux) will that still let me use all my CPU cores? –  makhlaghi Dec 27 '12 at 2:02
    
I tried it out with screen and it did divide the jobs through the different cores just as the different terminals do. Thank you very much, this will really help me in my future work. –  makhlaghi Dec 27 '12 at 3:11
    
I'm glad it helped. But please send a thank you note to the developpers of GNU screen : that kind of random thank you note will boost their energy and will reward them for all the hard work they spent on creating it and making it available to everyone :) –  Olivier Dulac Dec 27 '12 at 11:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.