Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some job to run which need be attached to terminal (or in foreground). The job is run in remote servers, and needs keep running after the users logout. I am aware of vnc server, however, I want to know if there is any builtin tool in redhat that can work this out. (that is, I dont have sudo to install extra software).

share|improve this question
You can force allocation of a terminal over ssh. Personally, I would use GNU screen. – jordanm Oct 4 '12 at 19:23
I need the job to be attached to terminal in the server. if I use ssh -t, it is the local terminal that is attached... the job could get interrupted if I logout locally. – Richard Oct 4 '12 at 19:28
Why does it need to be attached to a terminal? What is preventing it from running in the background? – jordanm Oct 4 '12 at 19:29
that is a good question. the goal of the job is to bypass certain idle detection mechanism on that server. if the job is running in background, the mechanism thinks it's idle... – Richard Oct 4 '12 at 19:41
That shouldn't be a problem if the process is completely detached from any terminal, unless the idle detection does crazy stuff like kill random processes because it feels like it (I assume you are really talking about an auto-timeout on a terminal session). – jordanm Oct 4 '12 at 19:45
up vote 1 down vote accepted

GNU screen is what you're looking for. It's pre-installed on all *nix systems I've used, so should be on Red Hat. screen acts as a terminal server, which can be attached and detached from terminal clients. It allows interesting possibilities such as having the same terminal session being viewed by multiple clients at the same time, multiple tabs, (horizontal) split screen, remote detaching (of other clients), etc.

If your ssh connection breaks unpredictably, your previous running command won't know about it and will continue to run as normal. You might have 10 different programs running in 10 different tabs within screen, and they'll all continue to run. You can then reattach (after logging in), with a few different variants of the same command - the one I use is:-

 screen -RD

This means to reattach your previous screen session to the current terminal, and IIRC detaches whatever other client(s) might still be connected.

To send a command to screen, when you're within a session, by default you use the "Ctrl+a" prefix, before pressing another letter, to for example, create or close a window. There are loads of screen cheat sheets online, and of course there's always the man page for more information if you need.

Screen has been around for a long time, so there are newer alternatives. I switched to tmux a year or so ago, and haven't looked back. This probably would require compiling, but it allows vertical split screen, which is the main reason why I favour it.

The above solutions sidestep your question though. They provide you with solutions provided you haven't started your program yet. If you have a long running program which wasn't created within a screen or tmux session, then you can still recover it. You won't be able to recover the command line history, AFAIK, but you can recover control of the process. The program I've used for this is reptyr, which I've successfully built and used on Mac OSX and Debian Linux flavours. IIRC, this requires sudo privileges to run though.

share|improve this answer

To start a "hidden" foreground terminal:

ssh server.com -t screen -S applicationName [/usr/bin/executable]

To detach (hide): CTRL+A D
To attach (resume): ssh server.com -t screen -r applicationName

share|improve this answer

Your Answer


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.