📄 1.1.t
字号:
.\" Copyright (c) 1983, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)1.1.t 8.1 (Berkeley) 6/8/93.\".sh "Processes and protection.NH 3Host and process identifiers.PPEach UNIX host has associated with it a 32-bit host id, and a hostname of up to 64 characters (as defined by MAXHOSTNAMELEN in\fI<sys/param.h>\fP).These are set (by a privileged user)and returned by the calls:.DSsethostid(hostid)long hostid;hostid = gethostid();result long hostid;sethostname(name, len)char *name; int len;len = gethostname(buf, buflen)result int len; result char *buf; int buflen;.DEOn each host runs a set of \fIprocesses\fP.Each process is largely independent of other processes,having its own protection domain, address space, timers, andan independent set of references to system or user implemented objects..PPEach process in a host is named by an integercalled the \fIprocess id\fP. This number isin the range 1-30000and is returned bythe \fIgetpid\fP routine:.DSpid = getpid();result int pid;.DEOn each UNIX host this identifier is guaranteed to be unique;in a multi-host environment, the (hostid, process id) pairs areguaranteed unique..NH 3Process creation and termination.PPA new process is created by making a logical duplicate of anexisting process:.DSpid = fork();result int pid;.DEThe \fIfork\fP call returns twice, once in the parent process, where\fIpid\fP is the process identifier of the child,and once in the child process where \fIpid\fP is 0.The parent-child relationship induces a hierarchical structure onthe set of processes in the system..PPA process may terminate by executing an \fIexit\fP call:.DSexit(status)int status;.DEreturning 8 bits of exit status to its parent..PPWhen a child process exits orterminates abnormally, the parent process receivesinformation about anyevent which caused termination of the child process. Asecond call provides a non-blocking interface and may also be usedto retrieve information about resources consumed by the process during itslifetime..DS#include <sys/wait.h>pid = wait(astatus);result int pid; result union wait *astatus;pid = wait3(astatus, options, arusage);result int pid; result union waitstatus *astatus;int options; result struct rusage *arusage;.DE.PPA process can overlay itself with the memory image of another process,passing the newly created process a set of parameters, using the call:.DSexecve(name, argv, envp)char *name, **argv, **envp;.DEThe specified \fIname\fP must be a file which is in a format recognizedby the system, either a binary executable file or a file which causesthe execution of a specified interpreter program to process its contents..NH 3User and group ids.PPEach process in the system has associated with it two user-id's:a \fIreal user id\fP and a \fIeffective user id\fP, both 16 bitunsigned integers (type \fBuid_t\fP).Each process has an \fIreal accounting group id\fP and an \fIeffectiveaccounting group id\fP and a set of\fIaccess group id's\fP. The group id's are 16 bit unsigned integers(type \fBgid_t\fP).Each process may be in several different access groups, with the maximumconcurrent number of access groups a system compilation parameter,the constant NGROUPS in the file \fI<sys/param.h>\fP,guaranteed to be at least 8..PPThe real and effective user ids associated with a process are returned by:.DSruid = getuid();result uid_t ruid;euid = geteuid();result uid_t euid;.DEthe real and effective accounting group ids by:.DSrgid = getgid();result gid_t rgid;egid = getegid();result gid_t egid;.DEThe access group id set is returned by a \fIgetgroups\fP call*:.DSngroups = getgroups(gidsetsize, gidset);result int ngroups; int gidsetsize; result int gidset[gidsetsize];.DE.FS* The type of the gidset array in getgroups and setgroupsremains integer for compatibility with 4.2BSD.It may change to \fBgid_t\fP in future releases..FE.PPThe user and group id'sare assigned at login time using the \fIsetreuid\fP, \fIsetregid\fP,and \fIsetgroups\fP calls:.DSsetreuid(ruid, euid);int ruid, euid;setregid(rgid, egid);int rgid, egid;setgroups(gidsetsize, gidset)int gidsetsize; int gidset[gidsetsize];.DEThe \fIsetreuid\fP call sets both the real and effective user-id's,while the \fIsetregid\fP call sets both the realand effective accounting group id's.Unless the caller is the super-user, \fIruid\fPmust be equal to either the current real or effective user-id,and \fIrgid\fP equal to either the current real or effectiveaccounting group id. The \fIsetgroups\fP call is restrictedto the super-user..NH 3Process groups.PPEach process in the system is also normally associated with a \fIprocessgroup\fP. The group of processes in a process group is sometimesreferred to as a \fIjob\fP and manipulated by high-level systemsoftware (such as the shell).The current process group of a process is returned by the\fIgetpgrp\fP call:.DSpgrp = getpgrp(pid);result int pgrp; int pid;.DEWhen a process is in a specific process group it may receivesoftware interrupts affecting the group, causing the group tosuspend or resume execution or to be interrupted or terminated.In particular, a system terminal has a process group and only processeswhich are in the process group of the terminal may read from theterminal, allowing arbitration of terminals among several different jobs..PPThe process group associated with a process may be changed bythe \fIsetpgrp\fP call:.DSsetpgrp(pid, pgrp);int pid, pgrp;.DENewly created processes are assigned process id's distinct from allprocesses and process groups, and the same process group as theirparent. A normal (unprivileged) process may set its process group equalto its process id. A privileged process may set the process group of anyprocess to any value.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -