1

I have about 100 server processes running in background. Whenever I kill them, I get 100 messages (one for each server) that the corresponding pid was killed.

For example:

./kill_script.sh: line 196: 1996 Killed         myserver 1
./kill_script.sh: line 196: 1997 Killed         myserver 2

# and so on till myserver 100

I do not want these messages to get printed. In fact, until a few hours ago, these were not getting printed. I have no clue why are these getting printed now.

Edit: If that matters, I use KILL -9 to kill these processes. But so was I doing earlier.

2

It does this (really) because the shell's developers decided it would be helpful. You can make it quiet(er):

The relevant code in bash looks like this:

              else if (IS_FOREGROUND (job))
                {
#if !defined (DONT_REPORT_SIGPIPE)
                  if (termsig && WIFSIGNALED (s) && termsig != SIGINT)
#else
                  if (termsig && WIFSIGNALED (s) && termsig != SIGINT && termsig != SIGPIPE)
#endif
                    { 
                      fprintf (stderr, "%s", j_strsignal (termsig));

                      if (WIFCORED (s))
                        fprintf (stderr, _(" (core dumped)"));

                      fprintf (stderr, "\n");
                    }
                }

which (the IS_FOREGROUND) suggests that you're seeing the message when you don't put your script in the background.

  • But how come I was not facing this issue until a few hours ago. I have not changed a single line in my script. – Sonu Mishra Aug 8 '16 at 23:25
  • Not seeing your script: you may have a trap instruction which sometimes catches the signal, sometimes not depending on what your servers are doing. – Thomas Dickey Aug 8 '16 at 23:28
  • @SonuMishra This message is only printed with SIGKILL (kill -9), and it can not be trapped. – jordanm Aug 8 '16 at 23:30
  • The bash source says it's printed if the jobs are running in the foreground. In a quick read, I don't see it if the jobs were backgrounded. – Thomas Dickey Aug 8 '16 at 23:32
  • Exactly, my jobs are running in background – Sonu Mishra Aug 8 '16 at 23:35

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.