Background job getting stopped

2019-09-20 08:25发布

I have writen a simple bash program. I want to run it as a background process. But it's getting stopped. I do not want that to happen. Kindly help

/#!/bin/bash  

while [ 1 ]; do  
command1 | cut -f 3  
sleep 5;  
done  

OUTPUT:  
Linux# /tmp/program &  
[19] 20162  
Linux# Line 1  
0  

[19]+ Stopped /tmp/command

Output explanation:
Line 1 and 0 are the output , and this output should be displayed every 5 secs which is what i want.
What happens: After displaying Line 1 and 0, control hangs, I press enter, I get the Stopped message. Kindly help me get rid of this.

1条回答
看我几分像从前
2楼-- · 2019-09-20 09:11

the first line of your script:

/#!/bin/bash 

should actually be:

#!/bin/bash 

I assume this was just a typo when posting your question (but you might want to check that out, just in case). Now, if i replace "command1" with an ls -las, it works for me:

#!/bin/bash

while [ 1 ]; do
ls -las | cut -f 3
sleep 5;
done

notice that i've only changed your "command1" by an ls.

so what is "command1" exactly? your job may be stopped if that "command1" needs stdin input (just one of the cases)

查看更多
登录 后发表回答