In my .bashrc

alias ss="sudo sh -c '/usr/bin/nohup /usr/local/bin/sslocal -c /etc/ss.json > /var/log/ss.log 2>&1' & "

Run ss at the first time.

debian9@hwy:~/workspace$ ss
[1] 9710

Run ss at the second time

debian9@hwy:~/workspace$ ss
[2] 9728
[1]   Exit 1                  sudo sh -c '/usr/bin/nohup /usr/local/bin/sslocal -c /etc/ss.json > /var/log/ss.log 2>&1'

The second command result in exit of the first command.
Now run command cd

debian9@hwy:~/workspace$ cd
[2]+  Exit 1                  sudo sh -c '/usr/bin/nohup /usr/local/bin/sslocal -c /etc/ss.json > /var/log/ss.log 2>&1'  (wd: ~/workspace)
(wd now: ~)

Why cd result in exit of ss ?

| improve this question | | | | |

This is just the impression you get because your shell only outputs information on completed jobs when it outputs a prompt; quoting e.g. the bash manpage:

The shell learns immediately whenever a job changes state. Normally, bash waits until it is about to print a prompt before reporting changes in a job's status so as to not interrupt any other output. If the -b option to the set builtin command is enabled, bash reports such changes immediately. Any trap on SIGCHLD is executed for each child that exits.

So what’s happening is

  1. You start ss which runs in the background.
  2. The shell outputs the next prompt.
  3. The background job finishes, but the shell doesn’t output anything yet.
  4. You run your next command (anything, ss, cd etc.).
  5. The shell outputs the next prompt, and since it’s doing so, outputs the exit information for completed jobs...

You can see what’s really happening by running set -b so the shell won’t wait for a prompt before outputting a completed job’s exit status.

| improve this answer | | | | |

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.