Open System Services Programmer's Guide
} else if (pid == 0) { /* child process executing */
printf("trying execute of %s\n", buf);
printf("argv[0]=%s,argv[1]=%s,argv[2]=%s\n",
argv[0],argv[1],argv[2]);
/* Supply a name and processor number for the child process. */
procext.pe_name_options = _TPC_NAME_SUPPLIED; /* Note 3 */
procext.pe_process_name = "/G/HEINZ"; /* set process name */
procext.pe_cpu = 1; /* set processor number */
/* Pass parameter values to the child process. */
tdm_execvep(buf, argv, environ, &procext, &procresults);
/* If process execution failed, print error message. */
fprintf(stderr, "couldn't execute: %s\n", buf); /* Note 4 */
exit(2);
}
/* The parent process waits for the child process to terminate. */
if ( (pid = waitpid(pid, &status, 0)) < 0)
perror("waitpid error");
printf("%% ");
}
exit(0);
}
Note 1
The tdmext.h library header file defines the input structure containing Guardian process
attributes to be assigned to the new process. It also defines the output structure containing
optional process identification and error information.
Note 2
To set attributes in the new process, you must declare the procext (input) and procresults
(output) structures and initialize them with default values. Then you can set attributes using
literals defined in tdmext.h.
Note 3
To set the process name, request a system-generated process name before calling tdm_fork()
and pass your process name to tdm_evecvep(). If you attempt to pass your name to
tdm_fork() and use the same name in the call to tdm_execvep(), you get an error stating
that the process already has a name.
Note 4
After the call to tdm_fork(), the child process has its own unique OSS process ID, which
does not change. It also has a process handle that does change after the call to
tdm_execvep().
Example 30 creates a named process with a system-generated name using tdm_spawnp(). By
setting fields in the inherit structure, the child process becomes a member of a group other than
the parent’s process group, and the child process is the leader of the new process group.
Creating and Controlling Processes 121










