blob: 7b5e8c0c25ef722d4f6dff3356a2d82a04f0ac7e [file] [log] [blame]
Igor Sysoevd90282d2004-09-28 08:34:51 +00001
2/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Maxim Konovalovf8d59e32012-01-18 15:07:43 +00004 * Copyright (C) Nginx, Inc.
Igor Sysoevd90282d2004-09-28 08:34:51 +00005 */
6
7
Igor Sysoeva6717c42002-12-23 06:29:22 +00008#ifndef _NGX_PROCESS_H_INCLUDED_
9#define _NGX_PROCESS_H_INCLUDED_
10
11
Ruslan Ermilovfbd32d42012-03-21 13:58:51 +000012#include <ngx_setaffinity.h>
Igor Sysoev90c08142005-07-25 09:41:38 +000013#include <ngx_setproctitle.h>
14
15
Igor Sysoev160d7742003-11-19 16:26:41 +000016typedef pid_t ngx_pid_t;
17
Igor Sysoev31eb8c02005-09-23 11:02:22 +000018#define NGX_INVALID_PID -1
19
Igor Sysoev3c3ca172004-01-05 20:55:48 +000020typedef void (*ngx_spawn_proc_pt) (ngx_cycle_t *cycle, void *data);
21
22typedef struct {
23 ngx_pid_t pid;
24 int status;
Igor Sysoev87350f22004-06-15 07:55:11 +000025 ngx_socket_t channel[2];
Igor Sysoev3c3ca172004-01-05 20:55:48 +000026
27 ngx_spawn_proc_pt proc;
28 void *data;
29 char *name;
30
31 unsigned respawn:1;
Igor Sysoev07b280a2009-08-10 13:07:15 +000032 unsigned just_spawn:1;
Igor Sysoev3c3ca172004-01-05 20:55:48 +000033 unsigned detached:1;
Igor Sysoev3c3ca172004-01-05 20:55:48 +000034 unsigned exiting:1;
Igor Sysoev993dc062004-01-13 06:39:14 +000035 unsigned exited:1;
Igor Sysoev3c3ca172004-01-05 20:55:48 +000036} 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
Igor Sysoev630ad0c2004-04-16 05:14:16 +000047#define NGX_MAX_PROCESSES 1024
Igor Sysoeva6717c42002-12-23 06:29:22 +000048
Igor Sysoev630ad0c2004-04-16 05:14:16 +000049#define NGX_PROCESS_NORESPAWN -1
Igor Sysoev07b280a2009-08-10 13:07:15 +000050#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
Igor Sysoev3c3ca172004-01-05 20:55:48 +000054
55
Igor Sysoevb54698b2004-02-23 20:57:12 +000056#define ngx_getpid getpid
Igor Sysoev1bfa7bc2005-10-10 12:59:41 +000057
58#ifndef ngx_log_pid
Igor Sysoevb54698b2004-02-23 20:57:12 +000059#define ngx_log_pid ngx_pid
Igor Sysoev1bfa7bc2005-10-10 12:59:41 +000060#endif
61
Igor Sysoev3d58f8c2004-01-08 08:47:17 +000062
Igor Sysoev49783fc2004-01-13 16:43:23 +000063ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
Igor Sysoevd039a2e2005-02-22 14:40:13 +000064 ngx_spawn_proc_pt proc, void *data, char *name, ngx_int_t respawn);
Igor Sysoev6a930452004-03-04 16:34:23 +000065ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx);
Igor Sysoevceb99292005-09-06 16:09:32 +000066ngx_int_t ngx_init_signals(ngx_log_t *log);
Igor Sysoev1b735832004-11-11 14:07:14 +000067void ngx_debug_point(void);
Igor Sysoeva1796d72004-06-23 05:54:27 +000068
Igor Sysoevc0edbcc2004-10-21 15:34:38 +000069
70#if (NGX_HAVE_SCHED_YIELD)
Igor Sysoev078d1b22004-06-30 15:30:41 +000071#define ngx_sched_yield() sched_yield()
Igor Sysoevc0edbcc2004-10-21 15:34:38 +000072#else
73#define ngx_sched_yield() usleep(1)
74#endif
75
Igor Sysoev078d1b22004-06-30 15:30:41 +000076
Igor Sysoev924bd792004-10-11 15:07:03 +000077extern int ngx_argc;
78extern char **ngx_argv;
79extern char **ngx_os_argv;
Igor Sysoev3c3ca172004-01-05 20:55:48 +000080
Igor Sysoev25b36fe2004-02-03 16:43:54 +000081extern ngx_pid_t ngx_pid;
Igor Sysoev87350f22004-06-15 07:55:11 +000082extern ngx_socket_t ngx_channel;
Igor Sysoevf7290502004-06-18 16:22:16 +000083extern ngx_int_t ngx_process_slot;
84extern ngx_int_t ngx_last_process;
Igor Sysoev3c3ca172004-01-05 20:55:48 +000085extern ngx_process_t ngx_processes[NGX_MAX_PROCESSES];
Igor Sysoev160d7742003-11-19 16:26:41 +000086
87
Igor Sysoeva6717c42002-12-23 06:29:22 +000088#endif /* _NGX_PROCESS_H_INCLUDED_ */