LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2011, 12:51 PM   #1
own3mall
LQ Newbie
 
Registered: Aug 2009
Posts: 20

Rep: Reputation: 0
SSH Sessions - How do they work in terms of applications?


I've been using SSH for a long time to remotely access my machine, but I don't understand how SSH sessions work in terms of the programs that run under these sessions.

For example, I don't understand why the programs I launch under an SSH session are terminated if I terminate the session. Why don't they continue to run? The ultimate session runs on the local machine, correct? So, each time I create a new SSH session, why are my startup programs relaunched? Wouldn't that create multiple instances of several programs? I run a webserver on my Ubuntu machine, and it doesn't seem to be affected by sessions. If I terminate the session it is still running, but my wine program does not continue to run. Why is that?

Right now, I've set up my Ubuntu machine to run a wine program called Autokick as a Startup application. When I start a session, it loads and runs. However, if I close that session, it no longer runs. By adding a program to the startup applications, it loads when the actual local computer boots, correct? Thus, if I were to have Autokick run from the session that is created once the local machine loads Ubuntu, would Autokick continue to run even when I create new sessions over SSH?

I'm so confused. Please help me understand this better. I just don't know how apache can run all the time despite sessions, but a wine program cannot.

Is there no way to use SSH to login to the current session running on the local machine? I don't want to keep creating sessions, if it launches programs every time a session is created.

I use NoMachine on Ubuntu 10.04
own3mall is online now Report Post Edit/Delete Message
 
Old 04-10-2011, 02:12 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
There are a couple of concepts at play here. Most importantly is the concpet of a 'controlling terminal'. When you launch an application, it has a standard input, which is normally connected to the console/terminal supporting your login. The application cannot receive input without this terminal, so it quits if the terminal disconnects. The mechanism is that the kernel sends the process a SIGHUP (hangup; like when a modem drops its phone connection) signal. Unhandled, the default behavior on receipt of SIGHUP is to terminate.

A 'daemon' process is a process that does not require or have a controlling terminal, and so is happy to run without one. This is required for most system services, since a controlling terminal can only exist as a product of a login, and system services run without any login occurring. The web server that you note is just such a service. Many others can usually be found in /etc/init.d.

You can use a couple of different tricks to keep your processes alive after a login session terminates. You can run it under nohup (man nohup for details) to keep the process running after the terminal dies. You can run the application in a Gnu screen session. This is probably the most useful, as it allows you to interact with the process, and also to re-connect later from other sessions, even concurrently by multiple users, if so configured.

There are various states/events that trigger files to be read or processes invoked. Boot-time is one; login-time is another; creation of a new shell process is yet another common case where config files are read. Applications that launch at boot-time are called services, and there are a small number of standard systems used by the various Linux distros that determine what services get launched and killed, in what order, etc. When you login (as with SSH), your shell will read a prescribed list of configuration files (man bash for details), and when you create a new shell without logging in (like launching an xterm from your desktop), a subset of those config files will be read.

If you need to set up applications to be automatically launched, you can modify the existing scripts to do so. It is up to you to determine at what level your processes need to be launched. Wine applications will be especially troublesome, since they probably also require an X server, and that is not going to exist at all at boot time, and cannot be suspended with tools like screen.

--- rod.

Last edited by theNbomr; 04-11-2011 at 01:12 PM.
 
Old 04-11-2011, 01:02 AM   #3
own3mall
LQ Newbie
 
Registered: Aug 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks for the helpful information theNbomr. It's making more sense to me now.

Is there a way I can configure the program to run as a daemon? nohup doesn't seem to work. Or better yet, is there a way I can make the application launch only after the computer boots up Ubuntu which logs into my account and not have it launch during created sessions?

Last edited by own3mall; 04-11-2011 at 01:17 AM.
 
Old 04-11-2011, 01:19 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You can add applications to launch in /etc/rc.local. It is a shell script that executes after all of the init.d services are launched as part of the boot process. Is your application one that requires you to interact with it via a console? If so, then using screen to support it is probably your best bet, but that is tricky to so at boot time.
Please note that boot-time and login time are distinctly different phases of operation in Linux. It is quite possible to have a Linux host perform useful work without anyone ever logging in to it. File and network servers are types of hosts that commonly operate in this way.

I don't know of any way to make a program into a daemon without modifying the application itself. You would have to have the source code, and an understanding of the Linux process model, and some understanding of the internal workings of the program to effect such a change.

What about nohup 'doesn't seem to work'?
--- rod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a way to restrict ssh sessions to a specific ssh client? smbhat Linux - Networking 8 03-11-2009 07:36 AM
[priv] in SSH Sessions stefaandk Linux - Security 2 09-22-2006 12:05 PM
SSH help, concerning sessions frokid879 Linux - Newbie 4 11-11-2005 11:22 AM
some applications died when I use ssh when others work fine calix Linux - Networking 1 01-20-2005 05:43 PM
dead ssh sessions babroga Linux - Networking 3 03-03-2002 06:43 PM


All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration