Solved

SSH Logout and reload session with running applications

Posted on 2004-09-13
8
951 Views
Last Modified: 2012-05-05
Sorry if the title is a bit ambiguious, but here goes:

I currently have an application running on a remote server which I want to keep running after I logout via SSH.  I would then like to be able to log back into the machine at any time and see if this application is still running.  I don't know whether it is possible, but to go back into the session I had before so that I can stop or restart the application and use the front end without having to restart it (currently done by killing the open process)

Is it possible to do it this way or would I need to put the application in the background then bring it to the foreground when I want to regain access to it?

I really haven't got a clue and would be grateful for some help, thanks.

Garry
0
Comment
Question by:garry_m
8 Comments
 
LVL 18

Accepted Solution

by:
liddler earned 50 total points
ID: 12042119
Not exaclty sure what you need, but take a look at screen:
http://www.gnu.org/software/screen/
and
http://frogcircus.org/screen/ssh-agent
0
 
LVL 3

Expert Comment

by:pat5star
ID: 12042253
I'm mostly just posting here so I get emailed when someone else answers. I'm interested in this question as well.

This is my understanding: If you SSH into a machine, start a process, send it to the background, then log out, you are unable to 'reattach' to that process when you log back in again. You either have to stay logged in so you can bg/fg the process, or if you choose to log out and log in again later, you will have to use top/ps to find out whether it's running or not, and to end it early you will have to use kill. You won't be able to pause and restart it again.

I sure would like to be wrong on this.

-Pat



0
 
LVL 18

Expert Comment

by:liddler
ID: 12042581
Pat,
You don't need to post to get emails for a Question, just click on the subscribe link, near the bottom of the Q.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 3

Expert Comment

by:pat5star
ID: 12042604
liddler,

Cool, I didn't realize that. Thanks :)

-Pat
0
 
LVL 20

Assisted Solution

by:Gns
Gns earned 50 total points
ID: 12042778
... And Pat, liddler is quite right. Run the process you'd like to "attach/detach" to under a screen session and you'll be able to do just that. For a plain shell "session" it'd hold true that by ending the session, you'd return the terminal... and have no way of regaining it... Screen overcomes this nicely:-). In it just <Ctrl>-<a><d> to detach from the session/window, then later on just "screen -list" to see what's there to attach to, and "screen -r [if more than one session, perhaps specify the PID.TTY.HOST triple]" to reattach...
Liddlers second link above show an outline as for how to "automate" the process a bit (using ssh-agent). Very nice any way you use it:-).
And best of all, almost all distros carry screen by default, and most install it in the default setup.
man screen
would be a next logical step:-)

-- Glenn
--
0
 
LVL 1

Expert Comment

by:HollyRidge
ID: 12044598
Screen is a wonderful program on linux servers and will allow you most of the time to get back into a current session. You would just "x" out of the ssh window instead of using the exit command. Once you log back in run the command...

screen -ls

That will give you the list of sessions. You would then run the following command (substitute sessionhere for the actual session you want to get back to.)...

screen -dr sessionhere


Now another option you may have here is running your application into memory is to use the && after it such as...

./applicationfile&&
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now