POSIX 1003.1 is based on a UNIX operating system standard. A
discussion of each of the fundamental POSIX concepts follows.
Process
A process is an abstraction that represents an executing program.
Multiple processes execute independently and have separate address
spaces. Processes can create, interrupt, and terminate other
processes, subject to security restrictions. A process has
characteristics in common with both an MVS address space and an MVS
task. It is easier for processes to create or influence each other
than for an MVS address space to create or influence another
address space.
Note:
MVS 5.1 allows more than one process to be created in the same
address space. This is an extension of the POSIX process model.
Permissions
Each user of a POSIX system has a defined user ID and group ID. User
IDs and group IDs are integers; user names and group names are
strings. Permissions are defined in terms of the user ID and group
ID. For example, the permissions for a file can be defined as
readable and writable by the owner, by other members of the
owning
group, or by anyone.
Programs can have permissions that are associated with the ownership
of the program rather than with the user running the program. The
real user ID and real group ID are associated with the user running
the program. The effective user ID and effective group ID,
which could be affected by the program,
are used to
determine the current permissions for the process. The POSIX
permission
structure is coarser than the structure defined by mainframe security
products such as RACF; the ability to create a program with the
privileges of its owner is new to MVS. POSIX allows users with
appropriate privileges to suppress certain permissions checks; users
with such privileges are called super-users.
Signals
A signal is an interruption of a process. Signals can be generated by
the operating system; they may also be generated by one process and
sent to another. In general, a process can catch a signal to take
some program-specified action. If a program does not catch a signal,
the system takes some default action, which is most frequently to
terminate the process; the default action can also be to do nothing,
or either to halt or resume process execution.
Some signals cannot be caught. The signal SIGKILL
can be used to
terminate another process without allowing the target process to
intercept termination. Unless the user
has appropriate privileges, a process can send a signal only to other
closely related processes, for instance, ones that it created. MVS
does not have a concept that corresponds to the POSIX signal.
Under MVS, various types of interrupts are handled by a number of
unrelated facilities such as ESTAE
, STIMER
, and
STAX
.
Files
A POSIX file is a stream of bytes. A regular file is stored on disk
and supports random access. A special file has special properties.
An example of a special file is a user's terminal. Another example is
a pipe, which is a software connection between two processes;
characters written to the pipe by one process can be read by the other
process.
Processes can share files. A locking mechanism allows processes to
cooperate in sharing a file. Filenames may be as long as 1024 bytes
in OpenEdition. Case distinctions are honored in filenames;
calc.c
and Calc.c
reference separate files. This is in
contrast to MVS data sets, which are record-oriented, cannot generally
be shared, and whose names are limited to a small number of uppercase
characters. POSIX files are organized into file systems that are
stored in MVS data sets by OpenEdition. These data sets can be
mounted independently.
Directories
POSIX files are organized into directories. A directory is a file
that contains a list of other files and their attributes. Directories
can reference subdirectories to any number of levels. A complete
pathname includes a directory specification and a filename. The
pathname /u/fred/calc.c
refers to the file named
calc.c
, in the directory fred
, in the directory u
in
the system root directory. Both special and regular files are
referenced by hierarchical filenames. For example, the pathname for
the user's terminal is /dev/tty
. Each process has a current
working directory that defines a reference point for pathnames. If a
working directory for a process is /u/fred
, the pathname
calc.c
is interpreted as /u/fred/calc.c
. You can read a
directory and write applications that process some or all of the
files in a directory. Neither MVS catalogs nor PDS directories offer
the flexibility and convenience of POSIX directories.
Links
POSIX permits more than one pathname to refer to the same file. These
additional pathnames are called links. Links to a file need not
reside in the same directory as the file.
A file continues to exist as long as
there is a link to it. A related MVS concept is alias data set names,
but, because of the differences between catalogs and directories, the
correspondence is not very close. The POSIX 1003.1a draft standard
introduces the symbolic link concept.
A symbolic link is a link
based on the name of the
file that is linked to. Unlike regular links, it is possible to have
a symbolic link to a file in a different file system from the link.
Terminals and Sessions
A POSIX terminal is a special file. POSIX provides interfaces that
are valid only for terminal files. For example, tcflush
is an
interface that is used to discard unread terminal input. A terminal
may be either a physical ASCII asynchronous terminal, such as a
VT-100, or a pseudo-terminal, which is a software emulation of an
asynchronous terminal. OpenEdition supports only pseudo-terminals
created by the TSO OMVS command. When a process writes to an
OpenEdition pseudo-terminal, the output is received by the OMVS
command, which then writes the data to the user's TSO terminal. Input
is handled in the same way. Some POSIX terminal control functions,
such as defining the terminal's baud rate, have no effect on
OpenEdition because they are not meaningful for a pseudo-terminal.
A controlling terminal is a POSIX terminal that controls a set of processes called a session. In a normal UNIX system, a session is started when a user logs in; the controlling terminal is the terminal associated with the login. In OpenEdition, a session is usually started when a user executes the OMVS command.
A session may be divided into several process groups: a foreground
process group and one or more background process groups. Processes
are generally allowed to send signals only to other processes in their
process group. The controlling terminal can use special input
sequences to interrupt or halt the processes of the foreground process
group. For example, the control-C character causes a SIGINT to be
sent to each foreground process. Note that the OMVS command uses the
sequence ¢c to replace control-C,
which cannot be
entered from a 3270 keyboard.
Shells
The shell is a specialized application that is used to invoke other
programs; it implements a scripting language that can be used in a
similar fashion to CLIST or REXX under TSO. The shell is a UNIX
construct associated with OpenEdition. It is defined by a
related POSIX standard, 1003.2. Although the shell is not defined by
the POSIX 1003.1 standard, it uses many interfaces that are defined by
that standard. Under MVS, invoking an application from the shell is
the best way to run an application in a fully POSIX-compliant
environment. The shell resembles the TSO TMP (terminal monitor
program). Because the shell is not part of POSIX 1003.1
functionality, the SAS/C Library does not interact directly with it,
with the exception of the system
and popen
functions,
which can invoke an
OpenEdition command through the shell.
The errno Variable
As described in in Chapter 1, "Introduction to the SAS/C Library,"
in SAS/C Library Reference, Volume 1 ,
the external int
variable errno
contains the
number of the most
recent error or warning condition detected by the run-time library.
To use
this value, include the header file <errno.h>
.
POSIX and OpenEdition Error Numbers
The <errno.h>
header file contains definitions for the
macro identifiers that name system error status conditions.
When a SAS/C Library function sets an error status by assigning a
nonzero valued to errno
, the calling program can check
for a particular value by using the name defined in <errno.h>
.
The following OpenEdition related, POSIX defined errno
values are defined
in <errno.h>
:
E2BIG
exec
function too large
EAGAIN
EBUSY
EINUSE
)
ECHILD
EDEADLK
EFAULT
EFBIG
EINVAL
EARE
)
EISDIR
ELOOP
EMFILE
ELIMIT
)
EMLINK
EMVSEXPIRE
EMVSINITIAL
EMVSNOTUP
EMVSPASSWORD
ENAMETOOLONG
ENDENT
ENFOUND
)
ENFILE
ENODEV
ENOEXEC
ENOLCK
ENOSYS
ENOTDIR
ENOTEMPTY
ENOTTY
ENXIO
EPERM
EPIPE
EROFS
ESPIPE
EUNSUPP
)
ESRCH
EXDEV
GIO
EDEVICE
)
Note:
In addition to the values listed above,
common SAS/C errno
values are listed in
Chapter 1, "Introduction to the
SAS/C Library," in SAS/C Library Reference, Volume 1 . Also refer to <errno.h>
for socket-related errno
values. For a complete
listing of all errno
values, see the SAS/C Compiler and Library Quick Reference Guide .
Also note that OpenEdition frequently
uses a reason code to
provide additional information
about errors occuring in POSIX functions. See
"System Macro Information" in Chapter 1 of SAS/C Library Reference, Volume 1 for information
on accessing OpenEdition reason codes.
Internal Error Numbers
The following errno
values
represent OpenEdition internal errors. Contact
IBM Technical Support if you receive one of these errors. These
errno
values are described in more detail in the manual,
OpenEdition Assembler Callable Services.
EIBMCANCELLED
EIBMCONFLICT
EIBMSOCKINUSE
EIBMSOCKOUTOFRANGE
EMVSCATLG
EMVSCVAF
EMVSDYNALC
EMVSPFSFILE
EMVSPFSPERM
EMVSSAF2ERR
EMVSSAFEXTRERR
EOFFLOADBOXDOWN
EOFFLOADBOXERROR
EOFFLOADBOXRESTART
Consult The POSIX.1 Standard: A Programmer's Guide by Fred Zlotnick
(1991, Benjamin/Cummings Publishing) or the POSIX standards for information on
the POSIX errno
values; consult IBM OpenEdition documentation for
information on the EMVS- and EIBM- errno
values.
Because the errno
values resulting from POSIX functions are well
organized and well-defined, the SAS/C Library does not diagnose
many problems that can occur with these functions, even when it
diagnoses similar problems occurring with MVS files. This eases
porting programs from other open systems, since these systems do
not, in general, have library diagnostics. In general, the SAS/C
Library will issue diagnostics for failures of OpenEdition
functionality only when (a) the failure is certainly the result
of programmer error, or (b) the error is so esoteric that diagnosis
is unlikely without a message.
SAS/C OpenEdition Interfaces
SAS/C functions take advantage of OpenEdition functionality in the
following categories:
Table 19.1 SAS/C OpenEdition Interfaces
Function Extension | 10031a/1003.2 | Volume
+----------------------------+----------+---------------+--------+ | Process Control Functions | | | | |----------------------------|----------|---------------|--------| | atfork | Yes | | II | |----------------------------|----------|---------------|--------| | execl | | | II | |----------------------------|----------|---------------|--------| | execle | | | II | |----------------------------|----------|---------------|--------| | execlp | | | II | |----------------------------|----------|---------------|--------| | execv | | | II | |----------------------------|----------|---------------|--------| | execve | | | II | |----------------------------|----------|---------------|--------| | execvp | | | II | |----------------------------|----------|---------------|--------| | _exit | | | II | |----------------------------|----------|---------------|--------| | fork | | | II | |----------------------------|----------|---------------|--------| | getpid | | | II | |----------------------------|----------|---------------|--------| | getppid | | | II | |----------------------------|----------|---------------|--------| | oeattach | Yes | | II | |----------------------------|----------|---------------|--------| | oeattache | Yes | | II | |----------------------------|----------|---------------|--------| | times | | | II | |----------------------------|----------|---------------|--------| | w_getpsent | Yes | | II | |----------------------------|----------|---------------|--------| | wait | | | II | |----------------------------|----------|---------------|--------| | waitpid | | | II | |----------------------------|----------|---------------|--------| | Permission Functions | | | | |----------------------------|----------|---------------|--------| | chaudit | Yes | | I | |----------------------------|----------|---------------|--------| | chmod | | | II | |----------------------------|----------|---------------|--------| | chown | | | II | |----------------------------|----------|---------------|--------| | fchaudit | Yes | | II | |----------------------------|----------|---------------|--------| | fchmod | Yes | | I | |----------------------------|----------|---------------|--------| | fchown | Yes | | II | |----------------------------|----------|---------------|--------| | getegid | | | II | |----------------------------|----------|---------------|--------| | geteuid | | | II | |----------------------------|----------|---------------|--------| | getgid | | | II | |----------------------------|----------|---------------|--------| | getgrgid | | | II | |----------------------------|----------|---------------|--------| | getgrnam | | | II | |----------------------------|----------|---------------|--------| | getgroups | | | II | |----------------------------|----------|---------------|--------| | getgroupsbyname | Yes | | II | |----------------------------|----------|---------------|--------| | getlogin | | | II | |----------------------------|----------|---------------|--------| | getpwnam | | | II | |----------------------------|----------|---------------|--------| | getpwuid | | | II | |----------------------------|----------|---------------|--------| | getuid | | | II | |----------------------------|----------|---------------|--------| | initgroups | Yes | | II | |----------------------------|----------|---------------|--------| | __passwd | Yes | | II | |----------------------------|----------|---------------|--------| | setgid | | | II | |----------------------------|----------|---------------|--------| | setgroups | Yes | | II | |----------------------------|----------|---------------|--------| | setuid | | | II | |----------------------------|----------|---------------|--------| | umask | | | II | |----------------------------|----------|---------------|--------| | Signal Functions | | | | |----------------------------|----------|---------------|--------| | alarm | | | I | |----------------------------|----------|---------------|--------| | kill | | | I | |----------------------------|----------|---------------|--------| | ecbsuspend | Yes | | I | |----------------------------|----------|---------------|--------| | oesigsetup | Yes | | I | |----------------------------|----------|---------------|--------| | pause | | | I | |----------------------------|----------|---------------|--------| | sigaction | | | I | |----------------------------|----------|---------------|--------| | sigaddset | | | I | |----------------------------|----------|---------------|--------| | sigdelset | | | I | |----------------------------|----------|---------------|--------| | sigemptyset | | | I | |----------------------------|----------|---------------|--------| | sigfillset | | | I | |----------------------------|----------|---------------|--------| | sigismember | | | I | |----------------------------|----------|---------------|--------| | siglongjmp | | | I | |----------------------------|----------|---------------|--------| | sigpending | | | I | |----------------------------|----------|---------------|--------| | sigprocmask | | | I | |----------------------------|----------|---------------|--------| | sigsetjmp | | | I | |----------------------------|----------|---------------|--------| | sigsuspend | | | I | |----------------------------|----------|---------------|--------| | sleep | | | I | +----------------------------|----------|---------------|--------| | I/O Functions | | | | |----------------------------|----------|---------------|--------| | close | | | I | |----------------------------|----------|---------------|--------| | creat | | | I | |----------------------------|----------|---------------|--------| | dup | | | I | |----------------------------|----------|---------------|--------| | dup2 | | | I | |----------------------------|----------|---------------|--------| | fcntl | | | I | |----------------------------|----------|---------------|--------| | fdopen | | | I | |----------------------------|----------|---------------|--------| | fileno | | | I | |----------------------------|----------|---------------|--------| | fsync | Yes | | I | |----------------------------|----------|---------------|--------| | ftruncate | Yes | | I | |----------------------------|----------|---------------|--------| | lseek | | | I | |----------------------------|----------|---------------|--------| | open | | | I | |----------------------------|----------|---------------|--------| | pipe | | | I | |----------------------------|----------|---------------|--------| | read | | | I | |----------------------------|----------|---------------|--------| | w_ioctl | Yes | | I | |----------------------------|----------|---------------|--------| | write | | | I | |----------------------------|----------|---------------|--------| | Directory Functions | | | | |----------------------------|----------|---------------|--------| | chdir | | | I | |----------------------------|----------|---------------|--------| | closedir | | | I | |----------------------------|----------|---------------|--------| | getcwd | | | I | |----------------------------|----------|---------------|--------| | mkdir | | | I | |----------------------------|----------|---------------|--------| | opendir | | | I | |----------------------------|----------|---------------|--------| | readdir | | | I | |----------------------------|----------|---------------|--------| | rewinddir | | | I | |----------------------------|----------|---------------|--------| | rmdir | | | I | |----------------------------|----------|---------------|--------| | File Utilities | | | | |----------------------------|----------|---------------|--------| | access | | | I | |----------------------------|----------|---------------|--------| | fstat | | | I | |----------------------------|----------|---------------|--------| | link | | | I | |----------------------------|----------|---------------|--------| | lstat | Yes | | I | |----------------------------|----------|---------------|--------| | mkfifo | | | I | +----------------------------|----------|---------------|--------| | File Utilities | | | | |----------------------------|----------|---------------|--------| | mknod | Yes | | I | |----------------------------|----------|---------------|--------| | readlink | Yes | | I | |----------------------------|----------|---------------|--------| | rename | | | I | |----------------------------|----------|---------------|--------| | stat | | | I | |----------------------------|----------|---------------|--------| | symlink | Yes | | I | |----------------------------|----------|---------------|--------| | unlink | | | I | |----------------------------|----------|---------------|--------| | utime | | | I | |----------------------------|----------|---------------|--------| | Terminal Functions | | | | |----------------------------|----------|---------------|--------| | cfgetispeed | | | II | |----------------------------|----------|---------------|--------| | cfgetospeed | | | II | |----------------------------|----------|---------------|--------| | cfsetispeed | | | II | |----------------------------|----------|---------------|--------| | cfsetospeed | | | II | |----------------------------|----------|---------------|--------| | ctermid | | | I | |----------------------------|----------|---------------|--------| | isatty | | | I | |----------------------------|----------|---------------|--------| | tcdrain | | | II | |----------------------------|----------|---------------|--------| | tcflow | | | II | |----------------------------|----------|---------------|--------| | tcflush | | | II | |----------------------------|----------|---------------|--------| | tcgetattr | | | II | |----------------------------|----------|---------------|--------| | tcsendbreak | | | II | |----------------------------|----------|---------------|--------| | tcsetattr | | | II | |----------------------------|----------|---------------|--------| | ttyname | | | I | |----------------------------|----------|---------------|--------| | Sessions and Process Groups Functions | | | |---------------------------------------|---------------|--------| | getpgrp | | | II | |----------------------------|----------|---------------|--------| | setpgid | | | II | |----------------------------|----------|---------------|--------| | setsid | | | II | |----------------------------|----------|---------------|--------| | tcgetpgrp | | | II | |----------------------------|----------|---------------|--------| | tcsetpgrp | | | II | |----------------------------|----------|---------------|--------| | Environmental Interfaces | | | | |----------------------------|----------|---------------|--------| | clearenv | Yes | | I | |----------------------------|----------|---------------|--------| | fpathconf | | | II | |----------------------------|----------|---------------|--------| | Environmental Interfaces | | | | |----------------------------|----------|---------------|--------| | getdtablesize | Yes | | II | |----------------------------|----------|---------------|--------| | getenv | | | I | |----------------------------|----------|---------------|--------| | pathconf | | | II | |----------------------------|----------|---------------|--------| | pclose | Yes | | I | |----------------------------|----------|---------------|--------| | popen | Yes | | I | |----------------------------|----------|---------------|--------| | setenv | Yes | | I | |----------------------------|----------|---------------|--------| | sysconf | | | II | |----------------------------|----------|---------------|--------| | system | Yes | | I | |----------------------------|----------|---------------|--------| | uname | | | II | |----------------------------|----------|---------------|--------| | Miscellaneous Functions | | | | |----------------------------|----------|---------------|--------| | mount | Yes | | II | |----------------------------|----------|---------------|--------| | tzset | | | I | |----------------------------|----------|---------------|--------| | umount | Yes | | II | |----------------------------|----------|---------------|--------| | w_getmntent | Yes | | II | |----------------------------|----------|---------------|--------| | w_statfs | Yes | | II | +----------------------------|----------|---------------|--------+
_access
_close
_fcntl
_fsync
_lseek
_open
_read
_rename
_unlink
_write
OpenEdition also supports mixed mode programs that combine base MVS
and POSIX functionality, for instance,
to enable a user shell command to write a VSAM
file or to enable
a TSO command to create new processes and communicate with the
processes through pipes. The rest of this section discusses the
interaction between MVS and POSIX.
fork
When the fork
system call creates a duplicate of a process, not all of
the information is copied to the new address space.
Information that is copied includes:
fork
has the following consequences:
fork
. Most of these signals cannot occur
in an address space created by fork
.
fork
can define atfork
exits
to take the appropriate action before and after a call to fork
.
exec
functions is called (execl
,
execle
, execlp
, execv
, execve
, or
execvp
),
OpenEdition terminates
the current process and begins a new process. Every task in the
address space is terminated. A new job step is inserted to
reinitialize the address space and run the specified program.
The new program inherits many of the OpenEdition attributes of its caller, such as open files, blocked signals, current alarm status, and process id. The new program does not inherit MVS-oriented information such as DD statements (other than STEPLIB) and blocking of non-OpenEdition signals or dynamically loaded modules.
The only allocated storage in the new process is associated
with the program's arguments and environment variables. Any
information to be passed to a program called by one of the exec
functions must
be passed in argument or environment variables. You may want to
consider using the oeattach
function, rather than
fork
and exec
, if you want to share storage with a
child process.
Because the program called by the exec
function
begins execution with no DD
statements, problems can arise while accessing the transient library.
If the SAS/C transient library is not in linklist or LPALIB, you may
need to define the ddn_CTRANS environment variable before calling
an exec function to execute a SAS/C program. See "Executing C
Programs" in SAS/C Compiler and Library User's Guide, Fourth Edition for more information.
Standard Types
The SAS/C implementation of the POSIX.1 standard defines
the following standard
data types:
Table 19.2 Standard POSIX Data Types
Name Type Header File Use
cc_t char <termios.h> Terminal control character clock_t double <time.h> Clock tick time unit dev_t unsigned int <sys/types.h> Device number gid_t unsigned int <sys/types.h> Group ID ino_t unsigned long <sys/types.h> File serial number mode_t unsigned long <sys/types.h File access mode nlink_t int <sys/types.h> File link count off_t long <sys/types.h> Type for lseek position pid_t unsigned int <sys/types.h> Process ID or process group ID size_t int <sys/types.h> Result of sizeof operator speed_t unsigned char <termios.h> Terminal I/O speed ssize_t int <sys/types.h> Signed equivalent of size_t tcflag_t int <termios.h> Terminal control flag time_t double <time.h> Elapsed time unit uid_t unsigned int <sys/types.h> User ID
Refer to Chapter 3, "I/O Functions," in SAS/C Library Reference, Volume 1 for information on using
environment variables to replace DD statements in programs called by
exec*
.
Signal Handling and ABENDs
MVS and POSIX have different concepts of abnormal termination. Under
MVS, a task terminates abnormally as a result of the
ABEND supervisor call. Each ABEND is identified by a numeric code
which defines the reason for termination.
According to POSIX, a process terminates abnormally as the result of receiving a signal for which the default action is process termination. Abnormal termination is identified only by the signal name.
From an MVS perspective, any abnormal termination resulting from a
POSIX signal causes an ABEND with a system completion code of EC6
.
The signal number can be extracted from the MVS reason code associated
with the ABEND.
From a POSIX perspective, the situation is more complex. If a process
terminates as the result of an ABEND that is not the direct result of
a POSIX signal, the behavior depends on actions of the run-time
library. If the run-time library's ABEND handling is not active due to
the use of the =nohtsig
option, or if the library is incapable
of handling the ABEND because, for example, library control blocks
have been corrupted, the ABEND can complete. OpenEdition interprets
the completion by ABEND as termination by SIGKILL
.
If the library can handle the ABEND,
the ABEND is transformed into an OpenEdition signal: SIGABRT
for a
user ABEND, or SIGABND
for a system ABEND. If the program has
defined a handler for the signal, control is passed to the handler.
Otherwise, the library completes termination by sending the
appropriate signal to itself; this causes the process status, as seen
by the parent process, to indicate that signal.
When termination results from a program check such as an invalid
memory access, the library's traceback may show either the traditional
0Cx
ABEND code or an EC6
ABEND. For programs that use OpenEdition
signal handling, it is difficult to predict which ABEND code will be
reported.
Multiple Processes in an Address Space
The SAS/C oeattach
and oeattache
functions allow you to create a child
process that runs
in the same address space as the caller. Processes created in this
manner do not obey all the normal POSIX rules for processes. In
particular:
setuid
or setgid
program unless the program's
specified user ID or group ID is the same as the current user ID or
group ID.
exec
function, a new subtask of the
parent process is created, that is, the exec
call does not terminate
the address space. An attempt to exec
a
setuid
or
setgid
program
that does not match the current user ID or group ID will fail.
oeattach
.
oeattach
is called from a TSO address space,
the child process
can read from and write to the user's TSO terminal. However, some
other TSO-related functionality is unavailable, such as TSO external
scope environment variables and the tso:
feature of the system
function.
errno
to EMVSNOTUP
,
and
returns.
There are a few functions for which the 1003.1 standard does not
specify a way to fail because it is impossible for the function to
fail in the UNIX environment. For instance, in the UNIX environment,
getpid
cannot fail, because every program has a process ID. In
MVS, if OpenEdition is not installed or has failed, it is impossible
to obtain a process ID. In these cases, the library issues an ABEND
user 1230.