quit a worker process

Maxim Dounin mdounin at mdounin.ru
Sat Oct 20 11:49:51 UTC 2012


On Fri, Oct 19, 2012 at 04:03:13PM -0400, YongFeng Wu wrote:

> What is an easy way to have a worker process exit and the master process to
> start a new worker process? For example, in the case of the memory
> allocation fails.

You don't want to exit worker process unless the problem 
encountered is really fatal.  Obviously memory allocation failure 
is only fatal if it affects operation of the whole worker process 
and can't be handled in another way (e.g. retried later).

In most cases it's just enough to terminate a single affected 
request if memory allocation fails.  To do this it's usually 
enough to just return an error from a handler function.

If for some reason you are really need to terminate a worker 
process yourself, you may use ngx_abort() (which basically maps to 
abort()).  Note though, that it's something you should only use if 
there is no way to properly return error instead and you are sure 
the problem is fatal and the whole worker process cannot continue, 
as it will kill all requests handled by the process and will 
likely result in the process core dump written.  You should also 
be careful to don't call it while leaving shared memory in an 
inconsistent state, as this will result in an inconsistent 
behaviour of other processes.

Just a side note: as of now nginx itself never calls ngx_abort() 
unless explicitly configured to do so for debugging with the 
"debug_points" directive.

Maxim Dounin

More information about the nginx-devel mailing list