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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
01-27-2012, 12:03 AM
|
#1
|
|
LQ Newbie
Registered: Jan 2012
Posts: 10
Rep: 
|
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.
|
|
|
|
01-27-2012, 12:26 AM
|
#2
|
|
Member
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 766
Rep: 
|
Use the & after the program command.
example: that should send the program to background.
Regards
|
|
|
|
01-27-2012, 12:28 AM
|
#3
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
Hi -
To run a program in the background so you can exit the terminal, use "nohup":
|
|
|
|
01-27-2012, 12:31 AM
|
#4
|
|
LQ Newbie
Registered: Jan 2012
Posts: 10
Original Poster
Rep: 
|
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??
|
|
|
|
01-27-2012, 12:34 AM
|
#5
|
|
LQ Newbie
Registered: Jan 2012
Posts: 10
Original Poster
Rep: 
|
Yeah am trying to use nohup only.
I am using it lyk nohup xlogo & but killing the terminal also kills the xlogo..
|
|
|
|
01-27-2012, 12:54 AM
|
#6
|
|
LQ Newbie
Registered: Jan 2012
Distribution: Debian / Ubuntu
Posts: 12
Rep:
|
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.
|
|
|
|
01-27-2012, 01:02 AM
|
#7
|
|
LQ Newbie
Registered: Jan 2012
Posts: 10
Original Poster
Rep: 
|
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.
|
|
|
|
01-27-2012, 01:16 AM
|
#8
|
|
LQ Newbie
Registered: Jan 2012
Posts: 10
Original Poster
Rep: 
|
Can somebody please reply to my question??
|
|
|
|
01-27-2012, 01:19 AM
|
#9
|
|
LQ Newbie
Registered: Jan 2012
Posts: 10
Original Poster
Rep: 
|
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
|
|
|
|
01-27-2012, 02:52 AM
|
#10
|
|
LQ Newbie
Registered: Jan 2012
Posts: 10
Original Poster
Rep: 
|
is there nobody who can help me over this??
|
|
|
|
01-27-2012, 03:12 AM
|
#11
|
|
LQ Newbie
Registered: Jan 2012
Posts: 10
Original Poster
Rep: 
|
?????
|
|
|
|
01-27-2012, 06:01 AM
|
#12
|
|
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,388
|
Quote:
Originally Posted by Danny3031
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.
|
01-27-2012, 07:51 AM
|
#13
|
|
Member
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 576
|
Hi.
If I understand your problem correctly, you may be interested in screen and/or tmux.
|
|
|
|
01-27-2012, 10:36 AM
|
#14
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,270
|
Quote:
Originally Posted by Danny3031
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.
|
|
|
|
01-28-2012, 02:53 AM
|
#15
|
|
Member
Registered: Sep 2011
Location: Houston, TX
Distribution: openSuSE, Fedora, CentOS, Debian,, and others
Posts: 84
Rep: 
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:21 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|