0

I have a script that needs to be run on background, if I run the same script on foreground, the script runs good and it wont stop until we manually interrupt (ctrl^c).

I am sure that the below command runs the script in background.

sudo -u webs ./spagent_L1 &

Once the above command is executed it will give the job number and the process number.

[1] 10118

And immediately after that if i press enter two times, the job gets stopped.

[1]+ Stopped    sudo -u webs ./spagent_L1

if I check the jobs running in background it shows that the job has been stopped.

$> jobs
[1]+ Stopped    sudo -u webs ./spagent_L1

Whereas if I check for process running, it shows like the above mentioned script is running.

$> ps -eo user,ppid,pid,cmd,state | grep -i spagent
root 10118 9383 0 05:42 pts/1 00:00:00 sudo -u webs ./spagent_L1 T
ape  10122 3983 0 05:42 pts/1 00:00:00 grep -i spagent R

Unless I kill the process 10118 the jobs command shows the output that the process is stopped. Once the process is killed, the jobs command doesn't return anything.

So, does the above output mean if the process is still running? Could anyone please help me understand what is happening up there. and how to run the script in background without getting it stopped.

Thanks in advance.

18
  • @val0x00ff I have mentioned it in my question itself, the output of ps -ef | grep -i spagent Commented Jul 26, 2017 at 7:21
  • If I use ps-eo, then I am getting the following error. Am I missing anything. $> ps -eo | grep web ERROR: Format specification must follow -o. ********* simple selection ********* ********* selection by list ********* -A all processes -C by command name -N negate selection -G by real group ID (supports names) -a all w/ tty except session leaders -U by real user ID (supports names) -d all except session leaders -g by session OR by effective group name -e all processes -p by process ID Commented Jul 26, 2017 at 9:23
  • looks like grep is expecting some kind of input (a file maybe ?)
    – Archemar
    Commented Jul 26, 2017 at 9:23
  • @Archemar What do you mean by some kind of input? the output of ps-ef is passed to grep -i spagent Commented Jul 26, 2017 at 9:28
  • 2
    @sabarishjackson Also you can try this instead nohup sudo -u webs ./spagent_L1 > some_log_file 2>&1 & this will print the output to the file and then check it to see if you find the issue. nohup is a linux tool to run processes immune to hangups (even after the shell executed them is closed)
    – Chen A.
    Commented Jul 26, 2017 at 13:28

1 Answer 1

0

You can run the script in the background by doing: (sudo -u webs ./spagent_L1 &) you should then be able to close the terminal (if you are in DE) without closing that script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .