ngx_process.h revision e18a033b
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8#ifndef _NGX_PROCESS_H_INCLUDED_
9#define _NGX_PROCESS_H_INCLUDED_
10
11
12#include <ngx_setaffinity.h>
13#include <ngx_setproctitle.h>
14
15
16typedef pid_t       ngx_pid_t;
17
18#define NGX_INVALID_PID  -1
19
20typedef void (*ngx_spawn_proc_pt) (ngx_cycle_t *cycle, void *data);
21
22typedef struct {
23    ngx_pid_t           pid;
24    int                 status;
25    ngx_socket_t        channel[2];
26
27    ngx_spawn_proc_pt   proc;
28    void               *data;
29    char               *name;
30
31    unsigned            respawn:1;
32    unsigned            just_spawn:1;
33    unsigned            detached:1;
34    unsigned            exiting:1;
35    unsigned            exited:1;
36} ngx_process_t;
37
38
39typedef struct {
40    char         *path;
41    char         *name;
42    char *const  *argv;
43    char *const  *envp;
44} ngx_exec_ctx_t;
45
46
47#define NGX_MAX_PROCESSES         1024
48
49#define NGX_PROCESS_NORESPAWN     -1
50#define NGX_PROCESS_JUST_SPAWN    -2
51#define NGX_PROCESS_RESPAWN       -3
52#define NGX_PROCESS_JUST_RESPAWN  -4
53#define NGX_PROCESS_DETACHED      -5
54
55
56#define ngx_getpid   getpid
57
58#ifndef ngx_log_pid
59#define ngx_log_pid  ngx_pid
60#endif
61
62
63ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
64    ngx_spawn_proc_pt proc, void *data, char *name, ngx_int_t respawn);
65ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx);
66ngx_int_t ngx_init_signals(ngx_log_t *log);
67void ngx_debug_point(void);
68
69
70#if (NGX_HAVE_SCHED_YIELD)
71#define ngx_sched_yield()  sched_yield()
72#else
73#define ngx_sched_yield()  usleep(1)
74#endif
75
76
77extern int            ngx_argc;
78extern char         **ngx_argv;
79extern char         **ngx_os_argv;
80
81extern ngx_pid_t      ngx_pid;
82extern ngx_socket_t   ngx_channel;
83extern ngx_int_t      ngx_process_slot;
84extern ngx_int_t      ngx_last_process;
85extern ngx_process_t  ngx_processes[NGX_MAX_PROCESSES];
86
87
88#endif /* _NGX_PROCESS_H_INCLUDED_ */
89