Open System Services Programmer's Guide
Example 31 Creating and Controlling a Guardian Process Using Guardian Procedures
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dlaunch.h>
#include <zsysc>
#include <cextdecs.h(PROCESS_LAUNCH_, PROCESS_SUSPEND_, \
PROCESS_ACTIVATE_, PROCESS_STOP_)>
/* Initialize input parameter structure to default values. */
process_launch_parms_def proc_param = P_L_DEFAULT_PARMS_;
/* Process results structure. */
zsys_ddl_smsg_proccreate_def proc_results;
char *pname;
short errordetail;
short outlen;
char *proc_name;
int main(int argc, char *argv[]) {
short retcode;
/* If the name of a Guardian program to run is not provided, use a
default program name. */
if(argc > 1)
pname = argv[1];
else
pname = "$system.systools.vols";
proc_name = "$heinz"; /* make the process name unique */
/* Initialize input parameters without default values. */
proc_param.program_name = pname;
proc_param.program_name_len = (short)strlen(pname);
proc_param.process_name = proc_name;
proc_param.process_name_len = (short)strlen(proc_name);
proc_param.name_options = ZSYS_VAL_PCREATOPT_NAMEINCALL;
/* Create a new Guardian process. */
retcode = PROCESS_LAUNCH_ (
&proc_param, /* input parameter list */
&errordetail, /* details of error */
&proc_results, /* output results */
sizeof(proc_results), /* maximum size of output */
&outlen /* actual size of output */
);
/* If unsuccessful, print error message and exit. */
if (retcode != 0) {
fprintf(stderr, "retcode = %d\n", retcode);
fprintf(stderr, "Error detail = %d\n", errordetail);
exit(1);
}
printf("Process %s created successfully\n", proc_name);
sleep(10); /* wait ten seconds */
/* Suspend the child process. */
retcode = PROCESS_SUSPEND_
((short *)&proc_results.z_phandle,
);
if (retcode != 0) {
fprintf(stderr, "Process suspend failure, code = %d\n", retcode);
exit(1);
}
printf("Process %s suspended for 10 seconds\n", proc_name);
sleep(10); /* wait ten seconds */
124 Managing Processes