File: sysprocs.h

package info (click to toggle)
jove 4.16-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,804 kB
  • ctags: 2,864
  • sloc: ansic: 27,140; makefile: 399
file content (118 lines) | stat: -rw-r--r-- 3,560 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/************************************************************************
 * This program is Copyright (C) 1986-1996 by Jonathan Payne.  JOVE is  *
 * provided to you without charge, and with no warranty.  You may give  *
 * away copies of JOVE, including sources, provided that this notice is *
 * included in all the files.                                           *
 ************************************************************************/

/* The diversity of process management is complicated and difficult to handle.
 * - In some systems (noteably POSIX), a process id has type "pid_t"
 * - V7 only has wait.  POSIX has waitpid (with options).  BSD has
 *   wait3.  Someone has wait2.
 * - The status result set by wait and used by WIF* has type
 *   "union wait" in BSD, but "int" everywhere else.
 * - The WIF* functions are defined in <sys/wait.h> by BSD and POSIX.
 * - WTERMSIG seems to be a creation of POSIX
 * - Some systems have vfork(1) and perform better if it is used
 *   in place of fork(1).
 *
 * This header attempts to span this diversity.  We provide:
 * - POSIX pid_t
 * - wait_opt, to accept options (and use them, if possible).
 * - wait_status_t
 * - WIF*
 * - WTERMSIG
 */

#ifdef POSIX_PROCS

# include <sys/types.h>	/* defines pid_t */
# include <sys/wait.h>
  typedef int	wait_status_t;
# define wait_opt(stat_loc, options)	waitpid(-1, stat_loc, options)

#else /*!POSIX_PROCS*/

 typedef int	pid_t;

# ifdef BSD_WAIT

#  include <sys/wait.h>

  typedef union wait	wait_status_t;

#  ifndef WEXITSTATUS
#   define WEXITSTATUS(w)	((w).w_retcode)
#  endif

#  ifndef WTERMSIG
#   define WTERMSIG(w)	((w).w_termsig)
#  endif

#  ifndef WAIT3
#   define wait_opt(stat_loc, options)	wait2(stat_loc, options)
#  else
#   define wait_opt(stat_loc, options)	wait3(stat_loc, options, (struct rusage *)NULL)
#  endif

# else /*!BSD_WAIT*/

  typedef int	wait_status_t;

#  ifdef UNIX

#   define WIFSTOPPED(w)	((w & 0377) == 0177)
#   define WIFEXITED(w)	((w & 0377) == 0)
#   define WIFSIGNALED(w)	(((w >> 8) & 0377) == 0)
#   define WEXITSTATUS(w)	((w >> 8) & 0377)
#   define WTERMSIG(w)	(w & 0177)

#   define wait_opt(stat_loc, options)		wait(stat_loc)

#  endif /* UNIX */

# endif /*!BSD_WAIT*/
#endif /*!POSIX_PROCS*/

#ifndef FULL_UNISTD
# ifndef POSIX_UNISTD

/* ??? pid_t may be changed by default argument promotions.
 * If so, this prototype might be wrong.
 */
extern int	kill proto((pid_t /*pid*/, int /*sig*/));	/* signal.h */

extern pid_t	fork proto((void));
extern pid_t	getpid proto((void));
extern int	getuid proto((void));
extern int	setuid proto((int));
# endif /* !POSIX_UNISTD */

# ifdef USE_VFORK
extern int	UNMACRO(vfork) proto((void));
# endif
#endif /* !FULL_UNISTD */

/* This nest of #ifdefs is simply to define NEWPG() which makes
 * the current process a process group leader of a new process group.
 * ??? pid_t may be changed by default argument promotions.
 * If so, this prototype might be wrong.
 */
#ifdef POSIX_PROCS
# ifndef FULL_UNISTD
   extern int	UNMACRO(setpgid) proto((pid_t /*pid*/, pid_t /*pgid*/));
# endif
# define NEWPG()	setpgid(0, getpid())
#else /* !POSIX_PROCS */
# ifdef BSD_SETPGRP
#  ifndef FULL_UNISTD
   extern int	UNMACRO(setpgrp) proto((pid_t /*pid*/, pid_t /*pgrp*/));
#  endif
#  define NEWPG()	setpgrp(0, getpid())
# else /* !(defined(BSD_SETPGRP) || defined(POSIX_PROCS)) */
#  ifndef FULL_UNISTD
   extern int	UNMACRO(setpgrp) proto((void));
#  endif
#  define NEWPG()	setpgrp()
# endif /* !(defined(BSD_SETPGRP) || defined(POSIX_PROCS)) */
#endif /* !POSIX_PROCS */