Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to trigger a reload of the Nginx master process by using pkill and sudo.

The server reloads fine, but I was just curious if anyone knows why the command sudo pkill -HUP -f "nginx: master process" returns code 129?

# Running as root
$ pkill -HUP -f "nginx: master process"
$ echo $?

# Output is as expected:

# Running as a user (sudo is set to not prompt for a password)
% sudo pkill -HUP -f "nginx: master process
% echo $?

# Output is weird (considering sudo should be passing along the return
#                  code of the command it is executing):

Running on Ubuntu 12.04.1 LTS running on EC2 ... surprisingly Ubuntu 12.04.1 LTS running on a physical computer (not installed using cloud images) runs fine.

share|improve this question
up vote 5 down vote accepted

Usually, when the shell returns a status code above 128, it means that the process was killed by a signal. Subtract 128 to get the signal number. Your kill command was killed by signal 1, which is HUP.

pkill takes care never to kill itself. But it matched its parent, the sudo process.

There are several ways to avoid this:

  • Use pkill -x to consider only exact matches and not substrings (recommended if possible, this is the best way to avoid spurious matches).
  • Don't use the -f option.
  • (Last resort) Write a pattern that doesn't match itself, e.g. "[n]ginx: master process".
share|improve this answer
Awesome idea ... I used pkill -x and just used the regex patter "^nginx: master process.*$" which worked like a charm! Thank you! End result: sudo pkill -HUP -x -f "^nginx: master process.*$" – iserko Aug 17 '12 at 13:57

sudo returns 129 because pkill is sending the HUP signal to sudo. This is because sudo's command line matches the string you gave to pkill with -f. A process terminated by a signal exits with code 128 + the signal number. HUP is signal number 1, hence exit code 129.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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