intro.2

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 740 行 · 第 1/2 页

2
740
字号
.\" SCCSID: @(#)intro.2	3.1	11/23/87.TH intro 2.SH Nameintro \- introduction to system calls .SH Syntax.B #include <errno.h>.SH Description.NXR "intro(2) keyword".NXR "system call" "introduction".NXAM "system call" "\fIspecific system calls\fP"Section 2 describes the ULTRIX system calls, which are theentries into the ULTRIX kernel.  In this section, referencepages with the extension 2yp are specific to theYellow Pages (YP) service.  Those pages ending in 2nfs are specific to the Network File System (NFS) service..PPAdditionally, some Section 2 reference pages contain an ENVIRONMENT section that describes differences between the POSIX or SYSTEM V environment and the ULTRIX operating system..SH Environmental Compatibility.NXR "system call" "specifying System V environment".NXR "system call" "specifying POSIX environment"Some system calls contain System V and POSIX features thatare compatible with ULTRIX programs.  Thesefeatures are provided for applications that are beingported from System V or POSIX.Occasionally, the System V and POSIX features conflict with features present in the ULTRIX system.  For example, a functionperformed under the ULTRIX operating system can producedifferent results in the System V or POSIX environment.  Ifconflicts exist, the ENVIRONMENT section of the reference page highlights thesedifferences..PPNeither the System V compatibility features nor the POSIXcompatibility features are not contained in the standard Cruntime library. To use the compatibility features, you must set your programming environment to System Vor POSIX when you compile or link your programs.  To set the System V orPOSIXenvironment, do either of the following:.IP 1. 5Use the .I \-Yoption for the .PN cc command. For example, the following demonstrates compiling a program inthe System V environment first, and then in the POSIX environment:.EX% cc \-YSYSTEM_FIVE program.c% cc \-YPOSIX program.c.EE.IP 2. 5Globally set the environment variable PROG_ENV toSYSTEM_FIVE or to POSIX.  .spIf you are using the C shell,execute the following line or include it in your .PN .login file:.EXsetenv PROG_ENV SYSTEM_FIVE  .EEReplace ``SYSTEM_FIVE'' with ``POSIX'' if you are using the POSIX environment..spIf you are using the Bourne or the System V shell, execute thefollowing line or include it in your .PN .profile file:.EXPROG_ENV=POSIX ; export PROG_ENV.EEReplace ``POSIX'' with ``SYSTEM_FIVE'' if you are using the System Venvironment..LE.PPIn each instance, the .PN cccommand defines a preprocessor symbol, either SYSTEM_FIVE or POSIX.  When the SYSTEM_FIVE symbol is defined, the C preprocessor,.PN cpp ,selects the System V data structures and symbol definitions. When thePOSIX symbol is defined,.PN cppselects the POSIX data structures and symboldefinitions. .PPIn addition, if .PN cc invokes the .PN ldlinker, it resolves references to routines by searching the System V version of theStandard C library (.PN libcV.a)  or the POSIX version of the Standard C library (.PN libcP.a) before it searches.PN libc.a .The linker searches .PN libcV.awhen the SYSTEM_FIVE symbol is defined. It searches.PN libcP.awhen POSIX is defined..PPIn the System V environment, if you specify the.I \-lm option on either the .PN ccor the .PN ld  command line, the linker includes the System V math library, instead of the ULTRIX math library, in your program..SH Return ValuesMost system calls have one or more return values.An error condition is indicated by an otherwise impossible returnvalue.  This value is usually \-1.When a function returns an error condition, it also stores an error number in the external variable .PN errno .This variable is not cleared on successful calls.  Thus, you shouldtest.PN errno only after an error has occurred..PPAll return codes and values fromfunctions are of type .I intunless otherwise noted..PPFor a list of the errors and theirnames as given in <errno.h>, see the.MS errno 2 reference page..SH DefinitionsThe following terms are used in Section 2:.TP 5Descriptor.brAn integer assigned by the system when a file is referencedby .PN open ,.PN dup ,.PN pipe ,or a socket is referenced by .PN socket   or .PN socketpair The descriptor uniquely identifies an access path to that file or socket froma given process or any of its children..TP 5Directory.brA directory is a special type of file that containsreferences to other files, called links.By convention, a directorycontains at least two links called dot (.) and dot-dot (..).  Dot refers to the directory itself and dot-dot refers to its parent directory..TP 5Effective User Id, Effective Group Id, and Access Groups.brAccess to system resources is governed by the the effective user ID, the effective group ID, and thegroup access list..IP The effective user ID and effective group ID are initially theprocess's real user ID and real group ID respectively.  Eithercan be modified through execution of a set-user-ID or set-group-IDfile, or possibly by one of its ancestors.  For more information, see.MS execve 2 ..IPThe group access list is an additional set of group IDsused only in determining resource accessibility.  Access checksare performed as defined under the term File Access Permissions..TPFile Access Permissions.brEvery file in the file system has a set of access permissions.These permissions are used in determining whether a processmay perform a requested operation on the file, such as openinga file for writing.  Access permissions are established at thetime a file is created.  They can be changed with the .PN chmod call. .IPFile access is separated into three types: read, write, andexecute.  Directory files use the executepermission to control whether or not the directory can be searched..IPFile access permissions are interpreted by the system asthey apply to three different classes of users: the ownerof the file, those users in the file's group, and anyone else.Every file has an independent set of access permissions foreach of these classes.  When an access check is made, the systemdecides if permission should be granted by checking the accessinformation applicable to the caller..IPRead, write, and execute/search permissions ona file are granted to a process in the following instances:.RS 10.IP \(bu 5The process's effective user ID is that of the superuser..IP \(bu 5The process's effective user ID matches the user ID of the ownerof the file and the owner permissions allow the access..IP \(bu 5The process's effective user ID does not match the user ID of theowner of the file, but either the process's effectivegroup ID matches the group IDof the file or the group ID of the file is inthe process's group access listand the group permissions allow the access..IP \(bu 5Neither the effective user ID nor the effective group IDand group access list of the processmatch the corresponding user ID and group ID of the file,but the permissions for other users allow access..RE.IPRead, write, and execute/search permissions on a file are notgranted, as follows:.RS 10.IP \(bu 5If the process is trying to execute an image and the filesystem is mounted no execute, execute permission is denied.  .IP \(bu 5If the process's effective UID is not root, theprocess is attempting to access a character or block specialdevice, and the file system is mounted with nodev, access is denied..IP \(bu 5If the process's effective UID is not root, the process is tryingto execute an image with the.I setuidor.I setgidbitset in the file's permissions, and the file system is mountednosuid, execute permission is denied..RE.TP 5File Name.brNames consisting of up to {FILENAME_MAX} characters can be used to namean ordinary file, special file, or directory..IPThese characters can be selected from the set of all ASCII charactersexcluding null (0) and the ASCII code for backslash (\\\).  The parity bit (bit 8) must be 0..IPAvoid using asterisks (*), question marks (?), or brackets ([ ])as part of filenames because of the special meaning attached to these characters by the shell..TP 5Message Operation Permissions.brIn the .MS msgop 2 and .MS msgctl 2system call descriptions, the permission required for anoperation is specified by a token. The token argument isthe type of permission needed and it is interpreted as follows:.EX00400    Read by user00200    Write by user00060    Read, Write by group00006    Read, Write by others.EERead and write permissions are granted to a process ifone or more of the following are true:.RS 10.IP \(bu 5The effective user ID of the process is superuser..IP \(bu 5The effective user ID of the process matches.I msg_perm.[c]uidin the data structure associated withmsqid and the appropriate bit of the user portion(0600) of.I msg_perm.modeis set..IP \(bu 5The effective user ID of the process does not match.I msg_perm.[c]uid, butthe effective group ID of the process matches.I msg_perm.[c]gidand the appropriate bit of the group portion (060)of.I msg_perm.modeis set..IP \(bu 5The effective user ID of the process does not match.I msg_perm.[c]uidand the effective group ID of the process does not match.I msg_perm.[c]gid, butthe appropriate bit of the other portion (06) of.I msg_perm.modeis set..RE.IPIf none of the previous conditions are true, the read and writepermissions are denied..TP 5Message Queue Identifier.brA message queue identifier (msqid) is a unique positive integercreated by a .PN msgget system call.  Each msqid has a message queue and a datastructure associated with it.  The data structure is referredto as.I msqid_dsand contains the following members:.EX 0struct  ipc_perm msg_perm; /*operation permission struct*/ushort  msg_qnum;          /*number of msgs on q*/ushort  msg_qbytes;        /*max number of bytes on q*/ushort  msg_lspid;         /*pid of last msgsnd operation*/ushort  msg_lrpid;         /*pid of last msgrcv operation*/time_t  msg_stime;         /*last msgsnd time*/time_t  msg_rtime;         /*last msgrcv time*/time_t  msg_ctime;         /*last change time*/                           /*Times measured in secs since*/                           /*00:00:00 GMT, Jan.1, 1970*/.EEThe.I msg_permstructure is an .I ipc_perm structure that specifies the message operationpermission.  The .I msg_perm structure includes the followingmembers:.EXushort  cuid;     /*creator user id*/ushort  cgid;     /*creator group id*/ushort  uid;      /*user id*/ushort  gid;      /*group id*/ushort  mode;     /*r/w permission*/.EEThe.I msg_qnummember is the number of message currently on the queue.The.I msg_qbytesmember is the maximum number of bytes allowed on the queue.The.I msg_lspidmember is the process ID of the last process that performed a.PN msgrcv operation.The.I msg_lrpidmember is the process ID of the last process that performed a.PN msgopoperation.The.I msg_stimemember is the time of the last.PN msgop operation, .I msg_rtimeis the time of the last.PN msgrcv

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?