LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running process in background (https://www.linuxquestions.org/questions/linux-newbie-8/running-process-in-background-856342/)

aggrishabh 01-14-2011 11:55 AM

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.

AlucardZero 01-14-2011 12:10 PM

Yes, use nohup or start it in 'screen'.

Code:

nohup command-here >/dev/null 2>&1 &
(note this will discard all output)

aggrishabh 01-14-2011 01:47 PM

Hi AlucardZero,

I think this command dosent work in BASH shell.

AlucardZero 01-14-2011 02:29 PM

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.

Andy Alt 01-15-2011 12:56 AM

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]

AlucardZero 01-15-2011 10:03 AM

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

schneidz 01-15-2011 10:38 AM

Quote:

Originally Posted by aggrishabh (Post 4224495)
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).

Andy Alt 01-15-2011 10:54 AM

Quote:

Originally Posted by AlucardZero (Post 4225218)
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>

aggrishabh 01-19-2011 07:51 AM

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.

aggrishabh 01-19-2011 07:52 AM

adding to my last post is there any alternative to screen command as nohup command is not working as i am using BASH shell.

schneidz 01-19-2011 08:20 AM

^ 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


lonerider 01-19-2011 09:19 AM

Quote:

Originally Posted by aggrishabh (Post 4230075)
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.

Andy Alt 01-19-2011 12:06 PM

Quote:

Originally Posted by aggrishabh (Post 4230075)
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.


All times are GMT -5. The time now is 05:00 PM.