LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-14-2011, 11:55 AM   #1
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Rep: Reputation: 1
Running process in background


Hi All,

Is there any way to run a long process in background so that it still remain in running state even if the user logout the system.

NOTE: In BASH shell.
 
Old 01-14-2011, 12:10 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,822

Rep: Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610
Yes, use nohup or start it in 'screen'.

Code:
nohup command-here >/dev/null 2>&1 &
(note this will discard all output)
 
Old 01-14-2011, 01:47 PM   #3
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Original Poster
Rep: Reputation: 1
Hi AlucardZero,

I think this command dosent work in BASH shell.
 
Old 01-14-2011, 02:29 PM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,822

Rep: Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610
It doesn't matter what shell you're in; it will work if nohup (or screen) is installed.

Would you like to post the exact command you are running and exactly what you get back? Copy and paste and use code tags.
 
Old 01-15-2011, 12:56 AM   #5
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware32-stable, Debian32 stable, LFS 7.1
Posts: 385

Rep: Reputation: 44
coproc

Quote:

Coprocesses
A coprocess is a shell command preceded by the coproc reserved word. A
coprocess is executed asynchronously in a subshell, as if the command
had been terminated with the & control operator, with a two-way pipe
established between the executing shell and the coprocess.

The format for a coprocess is:

coproc [NAME] command [redirections]
 
Old 01-15-2011, 10:03 AM   #6
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,822

Rep: Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610
Where does one find this coproc? It's not in "man bash" on my bash 3.2.39 (Debian Lenny), nor is it a binary in Lenny
 
Old 01-15-2011, 10:38 AM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,106

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
Quote:
Originally Posted by aggrishabh View Post
Hi AlucardZero,

I think this command dosent work in BASH shell.
what does this output yeild ?
Code:
which nohup
also what are you trying to run ?
if it depends on xorg then it wont keep running when you exit (and kill xorg).

Last edited by schneidz; 01-15-2011 at 10:40 AM.
 
Old 01-15-2011, 10:54 AM   #8
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware32-stable, Debian32 stable, LFS 7.1
Posts: 385

Rep: Reputation: 44
Quote:
Originally Posted by AlucardZero View Post
Where does one find this coproc? It's not in "man bash" on my bash 3.2.39 (Debian Lenny), nor is it a binary in Lenny
I'm using
GNU bash, version 4.1.7(2)-release (i486-slackware-linux-gnu) on Slackware 13.1

The way to do it with screen is
screen -dmS -X <command to execute>
 
Old 01-19-2011, 07:51 AM   #9
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Original Poster
Rep: Reputation: 1
Thanks for all your inputs,

last confusion is

scenario- i login to server through PUTTY and the server has a property that if a user is inactive lets say 20 odd mins. then that user auto logout even if the user is running an long copy command. please tell me where to set this type of property, or tell me where to get this knowledge.

second thing is if i run that long time taking command through screen then would this auto logout property also inherit to the virtual sub-shell also.

Cannot open your terminal '/dev/pts/20' - please check. i am getting this for screen command is this means i have no access to screen then how to do this.

I know i am demanding lot of things. Any help highly appreciated.
 
Old 01-19-2011, 07:52 AM   #10
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Original Poster
Rep: Reputation: 1
adding to my last post is there any alternative to screen command as nohup command is not working as i am using BASH shell.
 
Old 01-19-2011, 08:20 AM   #11
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,106

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
^ please post the output of:
Code:
which nohup
ideally the solution would be:
Code:
nohup cp <source> <whatever-floats-your-boat>
edit: heres mine:
Code:
[schneidz@hyper ~]$ which nohup
/usr/bin/nohup
[schneidz@hyper ~]$ echo $SHELL
/bin/bash

Last edited by schneidz; 01-19-2011 at 08:23 AM.
 
Old 01-19-2011, 09:19 AM   #12
lonerider
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Rep: Reputation: 0
Quote:
Originally Posted by aggrishabh View Post
Thanks for all your inputs,

last confusion is

scenario- i login to server through PUTTY and the server has a property that if a user is inactive lets say 20 odd mins. then that user auto logout even if the user is running an long copy command. please tell me where to set this type of property, or tell me where to get this knowledge.
In PUTTY configuration under 'Connection' there is an option 'Seconds between keepalives(0 to turn off)' set this to some value say 600. This will send keep alive packets to the server every 10 mins and your session will not logout due to inactivity.
 
Old 01-19-2011, 12:06 PM   #13
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware32-stable, Debian32 stable, LFS 7.1
Posts: 385

Rep: Reputation: 44
Quote:
Originally Posted by aggrishabh View Post
second thing is if i run that long time taking command through screen then would this auto logout property also inherit to the virtual sub-shell also.
No, if the user logs out, or gets disconnected, the process running within the screen session will still run.

And when not using screen, putting an & at the end of a cp command will ensure the jobs will keep running if they get disconnected.
 
  


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
Running a background process and then logging off simplified Linux - General 10 10-10-2008 03:25 AM
Process running in background baddah Linux - General 3 02-22-2008 12:44 AM
running process in background forever danran Linux - General 2 11-19-2006 09:44 AM
Running kismet as a background process coolnicklas Linux - Software 2 01-04-2006 03:33 PM
background running process elbriga Programming 2 09-21-2004 06:08 PM


All times are GMT -5. The time now is 09:25 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration