Open System Services Programmer's Guide
processes do not have OSS process IDs and cannot belong to process groups or sessions, the
setsid() and setpgid() functions operate only on OSS processes.
Example 36 sets the user ID of the current process to the user ID of the user whose name is supplied
at the command line. This program must be run using the super ID.
Example 36 Setting the User ID of the Current Process Using setuid()
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
int main(int argc, char *argv[])
{
uid_t uid;
struct passwd *pp;
int retcode;
/* Read the name of the user from the command line.
If the user name is not valid, print an error message and exit.
If the user name is not provided, print a usage message and exit. */
if(argc > 1) {
pp = getpwnam(argv[1]);
if (!pp) {
fprintf(stderr, "Unknown user name\n" );
exit (1);
}
} else {
fprintf(stderr, "Usage: procinf2 user name\n" );
exit (1);
}
/* Set user ID to ID of user name entered at the command line. */
uid = pp->pw_uid;
/* Print user ID before and after changing it. */
printf("Current UID = %d\n", getuid());
retcode = setuid(uid);
printf("New UID = %d\n", getuid());
if(retcode != 0) {
fprintf(stderr, "Can't set UID to %d\n", uid);
exit(1);
} else
exit(0);
}
Using the Guardian API
The PROCESS_SETINFO_ and PROCESS_SETSTRINGINFO_ procedures allow you to change
information about OSS as well as Guardian processes. PROCESS_SETINFO_ operates on integer
process attributes, and PROCESS_SETSTRINGINFO_ operates on string attributes.
Example 37 (page 137) changes the execution priority of the current process using
PROCESS_SETINFO_ and sets the home terminal to a new window using
PROCESS_SETSTRINGINFO_.
136 Managing Processes