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