LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-27-2012, 01:03 AM   #1
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Rep: Reputation: Disabled
make commands keep running after leaving a terminal session or ssh session


I am trying to write a c++ code where i can run 3 parallel jobs via multithreading and want them to be alive even if i kill the terminal..But when ever i kill the terminal,the job also gets killed.Can i know how to do so?
Thanks in advance.
 
Old 01-27-2012, 01:26 AM   #2
ukiuki
Senior Member
 
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 1,030

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Use the & after the program command.
example:
Code:
$conky &
that should send the program to background.

Regards
 
Old 01-27-2012, 01:28 AM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

To run a program in the background so you can exit the terminal, use "nohup":

Code:
nohup myprog &
 
Old 01-27-2012, 01:31 AM   #4
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Yeah i know about the & operator but even if i am using it my code is not working.If i kill the terminal,my application also exits.
Lets say m trying to launch xlogo.so even if am using command : xlogo &. Then if i terminate the execution, xlogo goes in background.thats ok.but if i kill my terminal,then the xlogo is also killed but i want it to be alive.. So is there any way out so that i can keep my xlogo thing alive??
 
Old 01-27-2012, 01:34 AM   #5
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Yeah am trying to use nohup only.
I am using it lyk nohup xlogo & but killing the terminal also kills the xlogo..
 
Old 01-27-2012, 01:54 AM   #6
pyroscope
LQ Newbie
 
Registered: Jan 2012
Distribution: Debian / Ubuntu
Posts: 12

Rep: Reputation: 1
You have to use a daemonization double-fork WITHIN the application.

This is an example: https://github.com/jgshort/Narcissis...c_daemonizer.c

Use Google to find LOTS of similar snippets.
 
Old 01-27-2012, 02:02 AM   #7
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
It was way too complicated for me to understand. Can you explain me out in simple code example?
Or else i might show you my code over here.You check it and tell me where i m committing a mistake.

Last edited by Danny3031; 01-27-2012 at 02:05 AM.
 
Old 01-27-2012, 02:16 AM   #8
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Can somebody please reply to my question??
 
Old 01-27-2012, 02:19 AM   #9
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
I am not able to continue running xlogo if i kill my terminal.Can anybody please tell me what am i missing in my code?

Last edited by Danny3031; 01-27-2012 at 05:54 AM. Reason: Nobody is here to help me
 
Old 01-27-2012, 03:52 AM   #10
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
is there nobody who can help me over this??
 
Old 01-27-2012, 04:12 AM   #11
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
?????
 
Old 01-27-2012, 07:01 AM   #12
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Quote:
Originally Posted by Danny3031 View Post
Yeah am trying to use nohup only.
I am using it lyk nohup xlogo & but killing the terminal also kills the xlogo..
How are you "killing" the terminal?

If I run xlogo in the background, from a terminal, and exit the terminal gracefully (ie. exit or ctrl-d), then it keeps running.

If I kill the terminal using the X widget, then xlogo exits too. However, if I run xlogo using nohup, then it keeps running.

The title of your post indicated that you may also want to run xlogo via an SSH session, and I presume to keep it running even after the session has terminated. I do not believe this is possible, since it is SSH that is managing the port-forwarding of data, not the X11 server.


P.S. A little advice... when asking for help on this forum, continually requesting immediate help may actually dissuade other members from helping you. Always be patient. Sometimes it may take a day for someone to respond to your query.

Last edited by dwhitney67; 01-27-2012 at 07:06 AM.
 
1 members found this post helpful.
Old 01-27-2012, 08:51 AM   #13
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 640

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Hi.

If I understand your problem correctly, you may be interested in screen and/or tmux.
 
Old 01-27-2012, 11:36 AM   #14
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by Danny3031 View Post
It was way too complicated for me to understand. Can you explain me out in simple code example?
Or else i might show you my code over here.You check it and tell me where i m committing a mistake.
You posted back only 8 minutes after the reply to your question. How much can you possibly have tried in such a brief time? You do have to put in a little effort.
--- rod.
 
Old 01-28-2012, 03:53 AM   #15
War3zWad|0
Member
 
Registered: Sep 2011
Location: Houston, TX
Distribution: openSuSE, Fedora, CentOS, Debian,, and others
Posts: 84

Rep: Reputation: Disabled
I would have to agree with firstfire in regards to your question. I use screen every day at work to run multiple tasks and when I exit the machine after detaching the screen session the task continues to run until completion.

and example:
Code:
[warezwaldo@m0b1l3 ~]$ screen
[warezwaldo@m0b1l3 ~]$ top -cd1
top - 02:47:55 up 2 days, 14:43,  4 users,  load average: 0.19, 0.15, 0.06
Tasks: 171 total,   1 running, 170 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.9%us,  2.4%sy,  0.0%ni, 49.8%id, 44.4%wa,  0.5%hi,  0.0%si,  0.0%st
Mem:   2804540k total,  1864472k used,   940068k free,   721824k buffers
Swap:  4996208k total,        0k used,  4996208k free,   739076k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                        
30686 warezwal  20   0  396m  90m  32m S    6  3.3   0:24.16 /usr/lib/firefox/firefox-bin http://www.linuxquestions.org/questions/showthread.php?threadid=925
 1971 root      20   0 76420  57m  12m S    1  2.1  19:45.02 /usr/bin/Xorg -br :0 vt7 -nolisten tcp -auth /var/lib/xdm/authdir/authfiles/A:0-L1bGYa          
 8243 warezwal  20   0  311m  65m  29m S    1  2.4   5:05.16 kwin -session 101bf13f16c11b000131344581900000112470000_1327481044_934435                       
30799 warezwal  20   0  133m  44m  19m S    1  1.6   0:00.48 kdeinit4: konsole [kdeinit]                                                                     
30822 warezwal  20   0  2504  988  732 R    1  0.0   0:00.02 top -cd1                                                                                        
    1 root      20   0  2196  720  612 S    0  0.0   0:02.38 init [5]                                                                                        
    2 root      20   0     0    0    0 S    0  0.0   0:00.00 [kthreadd]                                                                                      
    3 root      RT   0     0    0    0 S    0  0.0   0:00.02 [migration/0]                                                                                   
    4 root      20   0     0    0    0 S    0  0.0   0:01.54 [ksoftirqd/0]                                                                                   
    5 root      RT   0     0    0    0 S    0  0.0   0:00.00 [watchdog/0]                                                                                    
    6 root      RT   0     0    0    0 S    0  0.0   0:00.02 [migration/1]                                                                                   
    7 root      20   0     0    0    0 S    0  0.0   0:10.36 [ksoftirqd/1]                                                                                   
    8 root      RT   0     0    0    0 S    0  0.0   0:00.00 [watchdog/1]                                                                                    
    9 root      20   0     0    0    0 S    0  0.0   0:06.95 [events/0]                                                                                      
   10 root      20   0     0    0    0 S    0  0.0   0:21.28 [events/1]                                                                                      
   11 root      20   0     0    0    0 S    0  0.0   0:00.00 [netns]                                                                                         
   12 root      20   0     0    0    0 S    0  0.0   0:00.00 [async/mgr]                                                                                     
   13 root      20   0     0    0    0 S    0  0.0   0:00.00 [pm]                                                                                            
   14 root      20   0     0    0    0 S    0  0.0   0:00.16 [sync_supers]                                                                                   
   15 root      20   0     0    0    0 S    0  0.0   0:00.25 [bdi-default]                                                                                   
[detached]

[warezwaldo@m0b1l3 ~]$ screen -ls
There is a screen on:
        30812.pts-1.m0b1l3      (Detached)
1 Socket in /var/run/uscreens/S-warezwaldo.
To exit screen use the following key sequence: CNTL+A+D then to return to your screen session (if only 1) use screen -x you will see that the task continues to run even if you disconnect from ssh. To exit screen just type exit.
 
  


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
SSH concurrent session limit and idle session time out lasygsd Linux - Newbie 3 10-30-2014 08:56 AM
running four commands in yakuake quad session musonio Programming 0 07-29-2011 08:26 PM
attach to an already running terminal-bash session kpachopoulos Linux - Newbie 1 03-31-2008 05:16 PM
leaving an SSH session without terminating a task?? stardotstar Linux - Networking 7 03-03-2006 09:59 PM
Start a SSH Session in the Terminal stuartmunro Linux - Newbie 4 06-15-2005 05:23 PM


All times are GMT -5. The time now is 06:35 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration