Open System Services Programmer's Guide

}
return (err);
}
/*
* This procedure returns nonzero if the specified OSS PID identifies
* an existing process. Process handle is retrieved as a test.
*/
int valid_pid(pid_t pid)
{
short err;
short err_detail;
short len;
short phandle[10];
short ret_attr = 48; /* get process handle */
err = PROCESS_GETINFOLIST_(/*cpu*/,/*pin*/,/*node*/,/*nodelen*/,/*phandle*/,
&ret_attr, 1, phandle, (short)sizeof(phandle), &len,
&err_detail, 3 /* get info for PID specified */ ,
/*srchattr*/, /*srchattrcnt*/,
/*srchval*/, /*srchvalcnt*/, pid);
return ( err == 0 );
}
int main(int argc, char *argv[]) {
int i = 1; /* argument counter */
int remote = 0; /* remote = 0 for local command execution */
/* remote = 1 for remote command execution */
char *pathstring; /* search PATH string */
char *progname;
/* If the name of an OSS program is not provided,
use the default program "who" */
if(argc > 1)
progname = argv[1];
else
progname = "who";
/* Get standard file pathnames */
if((error = fd_to_pathname(stdin, inpath)) != ENOERR
|| (error = fd_to_pathname(stdout, outpath)) != ENOERR
|| (error = fd_to_pathname(stderr, errpath)) != ENOERR) {
fprintf(stderr, "Bad file number\n");
exit(1);
}
/* Build the fdinfo structure header */
/* Allocate memory for structure with three fdentry's) */
fdinfo = (fdinfo_def *) malloc(sizeof(fdinit)
+ 2 * sizeof(fdinit.z_fdentry));
/* Copy initialized structure entries into new memory area */
memcpy(fdinfo, &fdinit, sizeof(fdinit));
fdinfo->z_len = sizeof(fdinit); /* size of structure */
fdinfo->z_timeout = -1; /* no timeout to be used */
fdinfo->z_umask = -1; /* use creation mask of caller */
fdinfo->z_cwd = "/tmp"; /* initial working directory */
fdinfo->z_fdcount = 3; /* number of files to be opened */
fdentry = &fdinfo->z_fdentry;
/* Build the fdinfo entry for stdin */
fdentry[0].z_fd = 0; /* file descriptor number */
fdentry[0].z_dupfd = -1; /* no dup of file desc. */
fdentry[0].z_name = inpath; /* standard in file name */
fdentry[0].z_oflag = O_RDONLY; /* open as read only */
fdentry[0].z_mode = 0755; /* file permission mode */
/* Build the fdinfo entry for stdout */
fdentry[1].z_fd = 1;
fdentry[1].z_dupfd = -1;
fdentry[1].z_name = outpath;
fdentry[1].z_oflag = O_WRONLY;
fdentry[1].z_mode = 0755;
/* Build the fdinfo entry for stderr */
fdentry[2].z_fd = 2;
128 Managing Processes