Chapter Contents |
Previous |
Next |
SIGOPER |
Updates to Header Files in Function Examples |
In Chapter 20, "POSIX Function Reference," replace the examples
for the chpriority
, getpgid
, and getsid
functions with
the examples that are provided here.
/*---------------------------+ | POSIX/UNIX header files | +----------------------------*/ #include <sys/types.h> #include <unistd.h> #include <sys/resource.h> /*---------------------------+ | ISO/ANSI header files | +----------------------------*/ #include <stdio.h> #include <stdlib.h> /*---------------------------+ | Name: main | | Returns: exit(EXIT_SUCCESS)| | or exit(EXIT_FAILURE) | +----------------------------| +---------------------------*/ int main() { /* generic return code */ int rc; /* which kind of process */ /* id to use */ int kind; /* process id */ pid_t id; /* is oeprty relative or */ /* absolute */ int form; /* process priority */ /* (version 1) */ int prty1; /* process priority */ /* (version 2) */ int prty2; /* process id from getpid() */ pid_t pid; /* process group id from */ /* getpgid() */ pid_t pgid; /* process user id from */ /* getuid() */ uid_t uid; /* get the user id for this */ /* process */ uid = getuid(); /* get the process id for */ /* this process */ pid = getpid(); /* get the group process id */ /* for this process */ pgid = getpgid(pid); if (pgid == -1) { perror("Call to getpgid failed"); exit(EXIT_FAILURE); } printf(" The process id: %d\n", (int)pid); printf("The process group id: %d\n", (int)pgid); printf(" The process user id: %d\n", (int)uid); /*------------------------------*/ /* Get the process priority */ /* using the process id */ /*------------------------------*/ printf("\nGet the Process Priority using the Process ID\n"); /* the id arg is the pid of a process */ kind = PRIO_PROCESS; /* version 1 */ id = (id_t)pid; /* Set errno to zero for */ /* error handling */ errno = 0; prty1 = getpriority(kind, id); /* ---------------------------------*/ /* Test for Error */ /* Note: */ /* getpriority() may return a '-1' */ /* return code for either a */ /* failure rc, or when the priority */ /* is in-fact '-1'. To distinguish */ /* between the two conditions, */ /* check the errno */ /* value for a non-zero value. */ /*----------------------------------*/ if (prty1 == -1 && errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } else { printf("The process priority (pid:version 1): %d\n", prty1); } /* version 2 */ /* 0 implies current processs id */ id = (id_t)0; /* Reset errno to zero for */ /* error handling */ errno = 0; prty2 = getpriority(kind, id); /* Test for Error */ if (prty2 == -1 && errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } else { printf("The process priority (pid:version 2): %d\n", prty2); } /*-----------------------------*/ /* Get the process priority */ /* using the group process id */ /*-----------------------------*/ printf("\nGet the Process Priority using the Group Process ID\n"); /* the id arg is the group process id */ kind = PRIO_PGRP; /* version 1 */ id = (id_t)pgid; /* Set errno to zero for error handling */ errno = 0; prty1 = getpriority(kind, id); /* Test for Error */ if (prty1 == -1 && errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } else { printf("The process priority (gpid:version 1): %d\n", prty1); } /* version 2 */ /* 0 implies current group processs id */ id = (id_t)0; /* Reset errno to zero for error handling */ errno = 0; prty2 = getpriority(kind, id); /* Test for Error */ if (prty2 == -1 && errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } else { printf("The process priority (gpid:version 2): %d\n", prty2); } /*-------------------------------------------*/ /* Get the process priority using the */ /* process User id */ /*-------------------------------------------*/ printf("\nGet the Process Priority of the User ID\n"); /* the id arg is the user id of the process */ kind = PRIO_USER; /* version 1 */ id = (id_t)uid; /* Set errno to zero for error handling */ errno = 0; prty1 = getpriority(kind, id); /* Test for Error */ if (prty1 == -1 && errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } else { printf("The process priority (uid:version 2): %d\n", prty1); } /* version 2 */ /* Reset errno to zero for error handling */ errno = 0; /* 0 implies current process user id */ id = (id_t)0; prty2 = getpriority(kind, id); /* Test for Error */ if (prty2 == -1 && errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } else { printf("The process priority (uid:version 2): %d\n", prty2); } /*-----------------------------------------------*/ /* Set the process priority using the */ /* process id */ /*----------------------------------------------*/ printf("\nSet the Process Priority using the Process ID\n"); /* the id arg is the pid of a process */ kind = PRIO_PROCESS; /* an id of 0 implies current processs id */ id = (id_t)0; /* Reset errno to zero for error handling */ errno = 0; /* Set process priority to 5 */ prty1 = 5; rc = setpriority(kind, id, prty1); /*------------------------------------------------*/ /* Test for Error */ /* Note: UNIX System Services sites must enable */ /* the use of the setpriority() function. */ /* If the use of setpriority() has not */ /* beenenabled, any use of setpriority() */ /* will fail with errno set to ENOSYS. */ /* */ /*------------------------------------------------*/ if (rc == -1) { perror("Call to setpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (pid): %d\n", prty2); } /*--------------------------------------------*/ /* Set the process priority using the group */ /* process id */ /*--------------------------------------------*/ printf("\nSet the Process Priority using the Group Process ID\n"); /* the id arg is the group id of the process */ kind = PRIO_PGRP; /* 0 implies current group processs id */ id = (id_t)0; /* Reset errno to zero for error handling */ errno = 0; /* Set process priority to 10 */ prty1 = 10; rc = setpriority(kind, id, prty1); /* Test for Error */ if (rc == -1) { perror("Call to setpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (gpid): %d\n", prty2); } /*-------------------------------------------*/ /* Set the process priority using the */ /*process User id */ /*-------------------------------------------*/ printf("\nSet the Process Priority of the User ID\n"); /* the id arg is the user id of the process */ kind = PRIO_USER; /* an id of 0 implies current user id */ id = (id_t)0; /* Reset errno to zero for error handling */ errno = 0; /* Set process priority to 15 */ prty1 = 15; rc = setpriority(kind, id, prty1); /* Test for Error */ if (rc == -1) { perror("Call to setpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (uid): %d\n", prty2); } /*-------------------------------------------*/ /* Change the process priority using the */ /* process id */ /*-------------------------------------------*/ printf("\nChange the Process Priority using the Process ID\n"); /* the id arg is the pid of a process */ kind = PRIO_PROCESS; /* an id of 0 implies current processs id */ id = (id_t)0; /* Reset errno to zero for error handling */ errno = 0; /* change using "absolute" */ /* priority - equivalent to setpriority() */ form = CPRIO_ABSOLUTE; printf("\tChange using CPRIO_ABSOLUTE\n"); /* Change process priority to 3 */ prty1 = 3; rc = chpriority(kind, id, form, prty1); /*------------------------------------------------*/ /* Test for Error */ /* Note: UNIX System Services sites must enable */ /* the use of the chpriority() function. */ /* If the use of chpriority() has not been */ /* enabled, any use of chpriority() will */ /* fail with errno set to ENOSYS. */ /* */ /*------------------------------------------------*/ if (rc == -1) { perror("Call to chpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (pid): %d\n", prty2); } /* change using "relative" priority */ form = CPRIO_RELATIVE; printf("\tChange using CPRIO_RELATIVE\n"); /* Bump process priority up by 2 */ prty1 = 2; rc = chpriority(kind, id, form, prty1); /* Test for Error */ if (rc == -1) { perror("Call to chpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (pid): %d\n", prty2); } /*---------------------------------------------*/ /* Change the process priority using the */ /* group process id */ /*---------------------------------------------*/ printf("\nChange the Process Priority using the Group Process ID\n"); /* the id arg is the group id of the process */ kind = PRIO_PGRP; /* 0 implies current group processs id */ id = (id_t)0; /* Reset errno to zero for error handling */ errno = 0; /* change using "absolute" */ /* priority - equivalent to setpriority() */ form = CPRIO_ABSOLUTE; printf("\tChange using CPRIO_ABSOLUTE\n"); /* Change process priority to 7 */ prty1 = 7; rc = chpriority(kind, id, form, prty1); /* Test for Error */ if (rc == -1) { perror("Call to chpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (gpid): %d\n", prty2); } /* change using "relative" priority */ form = CPRIO_RELATIVE; printf("\tChange using CPRIO_RELATIVE\n"); /* Bump process priority up by 3 */ prty1 = 3; rc = chpriority(kind, id, form, prty1); /* Test for Error */ if (rc == -1) { perror("Call to chpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (gpid): %d\n", prty2); } /*--------------------------------------*/ /* Change the process priority using */ /* the process User id */ /*--------------------------------------*/ printf("\nChange the Process Priority of the User ID\n"); /* the id arg is the user id of the process */ kind = PRIO_USER; /* 0 implies current group processs id */ id = (id_t)0; /* Reset errno to zero for error handling */ errno = 0; /* change using "absolute" */ /* priority - equivalent to setpriority() */ form = CPRIO_ABSOLUTE; printf("\tChange using CPRIO_ABSOLUTE\n"); /* Change process priority to 11 */ prty1 = 11; rc = chpriority(kind, id, form, prty1); /* Test for Error */ if (rc == -1) { perror("Call to chpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (uid): %d\n", prty2); } /* change using "relative" priority */ form = CPRIO_RELATIVE; printf("\tChange using CPRIO_RELATIVE\n"); /* Bump process priority up by 4 */ prty1 = 4; rc = chpriority(kind, id, form, prty1); /* Test for Error */ if (rc == -1) { perror("Call to chpriority failed"); exit(EXIT_FAILURE); } else { prty2 = getpriority(kind, id); /* Test for Error */ if (errno != 0) { perror("Call to getpriority failed"); exit(EXIT_FAILURE); } printf("The process priority is now (uid): %d\n", prty2); } exit(EXIT_SUCCESS); } /* end of main() */
/*------------------------------------+ | POSIX/UNIX header files | +-------------------------------------*/ #include <sys/types.h> #include <unistd.h> /*------------------------------------+ | ISO/ANSI header files | +-------------------------------------*/ #include <stdio.h> #include <stdlib.h> /*------------------------------------+ | Name: main | | Returns: exit(EXIT_SUCCESS) or | exit(EXIT_FAILURE) | +-------------------------------------*/ int main() { /* current process id from getpid() */ pid_t pid; /* process group id from getpgid() */ pid_t pgid; /*------------------------------------------*/ /* Get the group process id of the current */ /* process */ /* Note: Both version 1 and version 2 are */ /* equivalent to calling the */ /* getpgrp() function */ /*------------------------------------------*/ printf("\nGet the Group Process ID of the Current Process\n"); /* version 1 */ /* Set errno to zero for error handling */ errno = 0; /* get the process id for this process */ pid = getpid(); /* get the group process id for this process */ pgid = getpgid(pid); /* Test for Error */ if (pgid == -1) { perror("Call to getpgid failed"); exit(EXIT_FAILURE); } else { printf(" The process id: %d\n", (int)pid); printf("The process group id:%d\n", (int)pgid); } /* version 2 */ /* Reset errno to zero for error handling */ errno = 0; /* 0 implies current processs id */ pid = 0; /* get the group process id for this process */ pgid = getpgid(pid); /* Test for Error */ if (pgid == -1) { perror("Call to getpgid failed"); exit(EXIT_FAILURE); } else { printf("The process group id: %d\n", (int)pgid); } exit(EXIT_SUCCESS); } /* end of main() */
/*------------------------------------+ | POSIX/UNIX header files | +-------------------------------------*/ #include <sys/types.h> #include <unistd.h> /*------------------------------------+ | ISO/ANSI header files | +-------------------------------------*/ #include <stdio.h> #include <stdlib.h> /*--------------------------------------+ | Name: main | | Returns: exit(EXIT_SUCCESS) | | or exit(EXIT_FAILURE) | + -------------------------------------*/ int main() { /* current process id from getpid() */ pid_t pid; /* process group id from getsid() */ pid_t sid; /*---------------------------------------*/ /* Get the Session Leader id for the */ /* Current Process */ /*---------------------------------------*/ printf("\nGet the Session Leader ID of the Current Process\n"); /* version 1 */ /* Set errno to zero for error handling */ errno = 0; /* get the process id for this process */ pid = getpid(); /* get the session leader id for */ /* this process */ sid = getsid(pid); /* Test for Error */ if (sid == -1) { perror("Call to getsid failed"); exit(EXIT_FAILURE); } else { printf(" The process id: %d\n", (int)pid); printf("The Session Leader id: %d\n", (int)sid); } /* version 2 */ /* Reset errno to zero for error handling */ errno = 0; /* 0 implies current processs id */ pid = 0; /* get the session leader id for */ /* this process */ sid = getsid(pid); /* Test for Error */ if (sid == -1) { perror("Call to getsid failed"); exit(EXIT_FAILURE); } else { printf(" The process id: %d\n", (int)pid); printf("The Session Leader id: %d\n", (int)sid); } exit(EXIT_SUCCESS); } /* end of main() */
Replace the #include
statements in the chown
example with the
#include
statements that are provided here.
#include <sys/types.h> #include <grp.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h>
New oeattach Example |
In Chapter 20, "POSIX Function Reference," replace the oeattach
sample code under the
"Example" heading
with the following code:
#include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <stdio.h> #include <signal.h> #include <lclib.h> main() { int pipefds[2]; pid_t pid; char *const parmList[] = {"/bin/ls", "-l", "/u/userid/dirname", NULL }; char lsout[200]; /* buffer for out ls output */ int amt; int status; /* status code from ls */ fclose(stdout); /* avoid stdio interfering with fd 1 */ fclose(stdin); /* avoid stdio interfering with fd 0 */ close(STDOUT_FILENO); /* make sure fd's 0 & 1 are avail */ close(STDIN_FILENO); pipe(pipefds); /* create both ends of a pipe */ if (pipefds[0] == STDOUT_FILENO) { fprintf(stderr, "Warning: Input fileno is 1, should not occur.\n"); pipefds[0] = dup(pipefds[0]); close(STDOUT_FILENO); } if (pipefds[1] != STDOUT_FILENO) { fprintf(stderr, "Warning: Output fileno is not 1, should not occur.\n"); dup2(pipefds[1],STDOUT_FILENO); /* make write end of pipe fd 1 */ close(pipefds[1]); /* close write end */ } pid = oeattach("/bin/ls", parmList); /* run ls command as subtask */ close(STDOUT_FILENO); /* close write end of pipe in parent */ for(;;) { /* read from the pipe */ amt = read(pipefds[0], lsout, sizeof(lsout)); if (amt <= 0) break; fwrite(lsout, 1, amt, stderr); /* write ls output to stderr */ } wait(&status); /* wait for ls to complete */ close(pipefds[0]); /* close pipe input end */ if (WIFEXITED(status)) exit(WEXITSTATUS(status)); else /* if ls failed, use kill to fail the same way */ kill(0, WTERMSIG(status)); }
Update to loadm Function Description |
In Chapter 1, "Dynamic-Loading Functions," in the loadm
function
description, in the section titled, "Example
1.2 dynamic loading modules with multiple functions," replace the example
code in "STEP I. Put the following declarations a common header file
and name it DYNTABLE:" with the following example:
int func1(void) int func2(void) struct funcdef { /* structure definition for functions */ int (*func1)(); int (*func2)(); /* More functions can go here. */ }; typedef struct funcdef *fptrtable; /* pointer to list of funcdefs */
Updates to the osdynalloc Function |
In Chapter 3, "MVS Low-Level I/O Functions," update the osdynalloc
function
description with the following information.
Replace the corresponding lines in the table labeled, "SVC 99 Request Block Keywords," with the following entries:
Identifier | RB Field | Value | Description | Notes |
---|---|---|---|---|
msgbelowelsto | S99LSTO | none | Allocate SVC 99 messages below the 16 meg line | |
msgerrormsgrc | none | int* | Message processing error code (returned in register 15 by IEFDB476) |
Replace the corresponding lines in the table labeled, "Dynamic Allocation Keywords," with the following entries:
Identifier | JCL Equiv | SVC 99Key | Value | Format | Description | Notes |
---|---|---|---|---|---|---|
subsysattrssattrssatt | none | DALSSATT | char* | Res Word | Subsystem attributes | (6) |
subsysparmssparmssprm | SUBSYS= (,parm... ) | DALSSPRM | char[68] | Multiple | Subsystem Parameters | (4) |
Add the following lines to the table labeled, "Dynamic Allocation Keywords:"
Identifier | JCL Equiv | SVC 99Key | Value | Format | Description | Notes |
---|---|---|---|---|---|---|
buflbuflenbuflndcbbufldcbbuflendcbbufln | DCB=BUFL= | DALBUFL | int | Buffer length | ||
fdatfiledata | FILEDATA= | DALFDAT | char* | Res Word | TEXT/BINARY for HFS file | |
ovaffoveraffoverrideaff | DALOVAFF | none | Override affinity | |||
retclienttokretctkrtctokenrtctkrtctoken | none | DALRTCTK | char(*) | [81] | Return JES client token | |
ssreq | none | DALSSREQ | char[5] | Subsystem request | ||
uncntunitcount | none | DALUNCNT | int | Device count | ||
unit | UNIT= | DALUNIT | char[9] | Unit name |
Replace the corresponding lines in the table labeled, "Dynamic Allocation Inquiry Keywords," with the following entries:
Identifier | JCL Equiv | SVC 99Key | Value | Format | Description | Notes |
---|---|---|---|---|---|---|
path | PATH= | DINRPATH | char[256] | HFS filename for which information is needed | (1) | |
retpathcdisprtpathcdisprpathcdispretpcdisprtpcdisprpcdispretpcdsrtpcdsrpcdsretcndsrtcndsrcnds | returnPATHDISP=(n,c) | DINRPCDS | int* | Encoded | Return HFS file abnormal disposition |
Add the following lines to the table labeled, "Dynamic Allocation Inquiry Keywords:"
Identifier | JCL Equiv | SVC 99Key | Value | Format | Description | Notes |
---|---|---|---|---|---|---|
retfdatretfiledatartfdatrfiledatartfdatrtfiledata | return FILEDATA= | DINRFDAT | int* | Encoded | Return TEXT/ BINARY attribute of HFS file | |
rettyprettyperttyprttype | none | DINRTTYP | char* | Encoded | Return data set type | |
retpathndispretpndispretpndsrpathndisprpndisprpndsrtpathndisprtpndisprtpnds | return PATHDISP= (n, ) | DINRPNDS | int* | Encoded | Return HFS file disposition | |
retvolumeretvolserretvolrtvolumertvolserrtvol | return VOL=SER= | DINRTVOL | char(*) | [7] | Return first volume serial |
Updates to the Socket Functions |
In Chapter 18, "Socket Function Reference," update the following sections as indicated:
selectecb
description to read:
The ecblist
argument is the address of
an array of structures, each of which represents one or more contiguous _ecblist
structures. Each structure contains two members,
a count of the number of ECBs, and the address of an array of ECBs. The count
may be zero, in which case the ECB array address is ignored.
setsocketopt
description:
Note: TCP_NODELAY
is not supported for non-integrated sockets. This is an IBM
restriction, and is not a SAS/C restriction. However, TCP_NODELAY
is supported for OE
(integrated)
sockets, which is the default for SAS/C Release 7.00. For releases prior to
7.00, you can use the setsockimp("OE")
function
to get integrated sockets.
Update to getdtablesize Example |
In Chapter 18, "Socket Function Reference," replace the code in the "Example" section with the following code:
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> main() { int maxsockets; fd_set *readset, *writeset, *exceptset); int ready; /* get maximum number of sockets */ maxsockets = getdtablesize(); /* allocate storage for fd sets (8 bits per byte, 4 byte int) */ readset = calloc((maxsockets+31)/32, 4); writeset = calloc((maxsockets+31)/32, 4); exceptset = calloc((maxsockets+31)/32, 4); /* allocate storage for fd sets (8 bits per byte) */ . . . ready = select(maxsockets, readset, writeset, exceptset, NULL); /* wait for socket activity */ . . . }
New <sys/un.h> Header File |
In Chapter 15, "The BSD UNIX Socket Library," add the following information for the <sys/un.h> header file:
<sys/un.h>
header file to
the list of header files:
17 <sys/un.h> |
The <sys/un.h> header file contains the definitions for UNIX domain sockets. <sys/socket.h> must be included in your code before <sys/un.h>.
sockaddr_un
as illustrated
in the following example, is the UNIX domain socket address structure.
struct sockaddr_un { unsigned char sun_len; /* sockaddr len including null */ sa_family_t sun_family; /* AF_UNIX / AF_LOCAL */ char sun_path[104]; /* path name */ };
The family type constant AF_LOCAL has replaced the equivalent, historical constant AF_UNIX in more recent practice. However, both constants are defined in the header file <sys/socket.h>, and either one may be used.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2004 by SAS Institute Inc., Cary, NC, USA. All rights reserved.