| 1 |
/* RCSid $Id: rtprocess.h,v 3.15 2016/03/04 02:48:14 greg Exp $ */ |
| 2 |
/* |
| 3 |
* rtprocess.h |
| 4 |
* Routines to communicate with separate process via dual pipes |
| 5 |
* |
| 6 |
* WARNING: On Windows, there's a system header named <process.h>. |
| 7 |
*/ |
| 8 |
#ifndef _RAD_PROCESS_H_ |
| 9 |
#define _RAD_PROCESS_H_ |
| 10 |
|
| 11 |
#include <errno.h> |
| 12 |
#include <stdio.h> |
| 13 |
#if defined(_WIN32) || defined(_WIN64) |
| 14 |
#include <windows.h> /* DWORD etc. */ |
| 15 |
typedef DWORD RT_PID; |
| 16 |
#include <process.h> /* getpid() and others */ |
| 17 |
#define getpid _getpid |
| 18 |
#define execv _execv |
| 19 |
#else |
| 20 |
#include <sys/param.h> |
| 21 |
#include <sys/types.h> |
| 22 |
typedef pid_t RT_PID; |
| 23 |
#endif |
| 24 |
|
| 25 |
#include "paths.h" |
| 26 |
|
| 27 |
#ifdef __cplusplus |
| 28 |
extern "C" { |
| 29 |
#endif |
| 30 |
|
| 31 |
/* On Windows, a process ID is a DWORD. That might actually be the |
| 32 |
same thing as an int, but it's better not to assume anything. |
| 33 |
|
| 34 |
This means that we shouldn't rely on PIDs and file descriptors |
| 35 |
being the same type, so we have to describe processes with a struct, |
| 36 |
instead of the original int[3]. For that purpose, we typedef a |
| 37 |
platform independent RT_PID. |
| 38 |
*/ |
| 39 |
|
| 40 |
|
| 41 |
#ifndef PIPE_BUF |
| 42 |
#ifdef PIPSIZ |
| 43 |
#define PIPE_BUF PIPSIZ |
| 44 |
#else |
| 45 |
#ifdef PIPE_MAX |
| 46 |
#define PIPE_BUF PIPE_MAX |
| 47 |
#else |
| 48 |
#define PIPE_BUF 512 /* hyperconservative */ |
| 49 |
#endif |
| 50 |
#endif |
| 51 |
#endif |
| 52 |
|
| 53 |
typedef struct { |
| 54 |
int r; /* read handle */ |
| 55 |
int w; /* write handle */ |
| 56 |
int running; /* doing something */ |
| 57 |
RT_PID pid; /* process ID */ |
| 58 |
} SUBPROC; |
| 59 |
|
| 60 |
#define SP_INACTIVE {-1,-1,0,0} /* for static initializations */ |
| 61 |
|
| 62 |
#define close_process(pd) close_processes(pd,1) |
| 63 |
|
| 64 |
extern int open_process(SUBPROC *pd, char *av[]); |
| 65 |
extern int close_processes(SUBPROC pd[], int nproc); |
| 66 |
extern int process(SUBPROC *pd, char *recvbuf, char *sendbuf, int nbr, int nbs); |
| 67 |
extern int readbuf(int fd, char *bpos, int siz); |
| 68 |
extern int writebuf(int fd, char *bpos, int siz); |
| 69 |
|
| 70 |
#if defined(_WIN32) || defined(_WIN64) |
| 71 |
/* any non-negative increment will send the process to IDLE_PRIORITY_CLASS. */ |
| 72 |
extern int win_kill(RT_PID pid, int sig /* ignored */); |
| 73 |
extern int win_nice(int inc); |
| 74 |
#endif |
| 75 |
|
| 76 |
|
| 77 |
#ifdef __cplusplus |
| 78 |
} |
| 79 |
#endif |
| 80 |
#endif /* _RAD_PROCESS_H_ */ |
| 81 |
|