LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 12: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, 12:26 AM   #2
ukiuki
Senior Member
 
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 1,030

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

Regards
 
Old 01-27-2012, 12:28 AM   #3
paulsm4
LQ 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, 12: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, 12: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, 12:54 AM   #6
pyroscope
LQ Newbie
 
Registered: Jan 2012
Distribution: Debian / Ubuntu
Posts: 15

Rep: Reputation: 2
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, 01: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 01:05 AM.
 
Old 01-27-2012, 01: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, 01: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 04:54 AM. Reason: Nobody is here to help me
 
Old 01-27-2012, 02: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, 03:12 AM   #11
Danny3031
LQ Newbie
 
Registered: Jan 2012
Posts: 10

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

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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 06:06 AM.
 
1 members found this post helpful.
Old 01-27-2012, 07:51 AM   #13
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

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

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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, 02: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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:55 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
Open Source Consulting | Domain Registration