The problem happened on one of my local machines with CentOS 6. I ssh to it from my MacBook trying to test a script, which is in /usr/local/bin. However, whenever I tried to execute the command, it is immediately suspended, displaying "[1]+ Stopped". I had to use fg to make it the foreground. Since it's 3 a.m. in the morning, I was wondering if it is related to nice. But I tried some command with nice and renice, it didn't work. As the script calls an I/O-bound Perl script, I also tried ionice but it didn't work either.

It seems difficult to reproduce the problem, since after a reboot the problem is gone. Does anyone know the reason?

  • Sounds like the script you're running has a line in it that's getting backgrounded. Look for a line that has an ampersand at the end of it, &. – slm Mar 12 '14 at 8:22
  • No, I didn't use any ampersands in my script. My script simply calls the Perl script. When I executed the Perl script, or even wget, the same thing happened. – moleculea Mar 12 '14 at 19:07
  • 1
    Please share your script, if possible, also I'd take a look at the settings for your shell, specifically the shopt command to see if you've accidentally enabled a unusual mode. – slm Mar 12 '14 at 19:18
  • @slm This is the script yaanyap, shopt output link and set -o output. link. Because after the reboot the problem was gone , the options may not be exactly the same as the issue occurred, though I remembered I didn't accidentally enable any mode. – moleculea Mar 13 '14 at 3:27
  • @slm I just use URLs from YouTube. – moleculea Mar 15 '14 at 22:38

The process is asking for something from the standard input. When a background task needs to read standard input, the task is stopped. Let's take a simple example:

cat | awk '{print ++linenum " " $0}'

Now, let's call this linenum.sh and run it in the background of a Bash script:

sh ./linenum.sh &

What happens?

[1] Stopped sh ./linenum.sh

Why is it stopped? Because it needs standard input to continue.

So, how do we stop the annoying Stopped message? By giving it something in the standard input!

cat /dev/null | sh ./linenum.sh &

This particular script will immediately terminate (since /dev/null is a 0-length file with read)

  • My script does not ask for stdin. Neither does the Perl script. I think the problem is something related to the system, since before the reboot, the Perl script or even wget was suspended. – moleculea Mar 12 '14 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.