.  UNIX. - V UNIX. , , , , . , , - , , - . - , -1, errno, external. , 0. - : , . - , UNIX, , , , - . access ______________________________ access(filename,mode) char *filename; int mode; access , , ( mode). mode 4 ( ), 2 ( ) 1 ( ). . acct ______________________________ acct(filename) char *filename; acct , filename , - . lar ______________________________ unsigned alarm(seconds) unsigned seconds; alarm (seconds). , . 400 brk ______________________________ int brk(end_data_seg) char *end_data_seg; brk ( ) end_data_seg. - , sbrk, . hdir ______________________________ chdir(filename) char *filename; chdir , filename. hmod ______________________________ chmod(filename,mode) char *filename; chmod mode, ( ): 04000 02000 01000 sticky bit 00400 00200 00100 00040 00020 00010 00004 00002 00001 how ______________________________ chown(filename,owner,group) char *filename; int owner,group; chown - , owner group. hroot ______________________________ 401 chroot(filename) char *filename; chroot - filename. los ______________________________ close(fildes) int fildes; close , - open, creat, dup, pipe fcntl, - fork. reat ______________________________ creat(filename,mode) char *filename; int mode; creat . mode , access, sticky-bit , , umask, . - - . d ______________________________ dup(fildes) int fildes; dup , - . - , - .  ______________________________ execve(filename,argv,envp) char *filename; char *argv[]; char *envp[]; execve filename, . argv - , , envp - , . 402 it ______________________________ exit(status) int status; exit , 8 . . fcntl ______________________________ fcntl(fildes,cmd,arg) int fildes,cmd,arg; fcntl , fildes. cmd arg ( - "/usr/include/fcntl.h"): F_DUPFD , arg F_SETFD "close-on-exec" - arg ( exec) F_GETFD "close-on-exec" F_SETFL , (O_NDELAY - - -, O_APPEND - ) F_GETFL , struct flock short l_type; /* F_RDLCK - , F_WRLCK - , F_UNLCK - */ short l_whence; /* - - (0), - - (1), (2) */ long l_start; /* , - l_whence */ long l_len; /* . 0, - l_start */ long l_pid; /* , - */ long l_sysid; /* - , */ F_GETLK , - arg . , l_type arg F_UNLCK 403 F_SETLK - arg. -1 F_SETLKW arg. - , , - . , , . fork ______________________________ fork() fork . - -. -- , - . getpid ______________________________ getpid() getpid . : getpgrp, , , getppid, , . getuid ______________________________ getuid() getuid - . : geteuid, - , getgid, , getegid, - . ioctl ______________________________ ioctl(fildes,cmd,arg) int fildes,cmd; ioctl - , fildes. , , cmd, - arg . kill ______________________________ 404 kill(pid,sig) int pid,sig; kill , - pid, , sig. pid - - pid pid = 0 , - pid = -1 - , - , - , , - - pid < -1 , pid - - , , - - -. link ______________________________ link(filename1,filename2) char *filename1,*filename2; link filename1 filename2. - . lseek ______________________________ lseek(fildes,offset,origin) int fildes,origin; long offset; lseek - fildes . origin: 0 , - 1 2 , - knod ______________________________ 405 mknod(filename,modes,dev) char *filename; int mode,dev; mknod , ( " - ") - modes: 010000 020000 - 040000 060000 - 12 modes , chmod. , dev - . ount ______________________________ mount(specialfile,dir,rwflag) char *specialfile,*dir; int rwflag; mount , - specialfile, dir. rwflag , . sgctl ______________________________ #include #include #include msgctl(id,cmd,buf) int id,cmd; struct msgid_ds *buf; , cmd, msgctl - id, . msquid_ds : struct ipc_perm { ushort uid; /* */ ushort gid; /* */ ushort cuid; /* - */ ushort cgid; /* */ ushort mode; /* */ short pad1; /* */ long pad2; /* */ }; struct msquid_ds { struct ipc_perm msg_perm; /* , */ 406 short pad1[7]; /* */ ushort msg_qnum; /* */ ushort msg_qbytes; /* */ ushort msg_lspid; /* , */ ushort msg_lrpid; /* , */ time_t msg_stime; /* */ time_t msg_rtime; /* - */ time_t msg_ctime; /* - */ }; : IPC_STAT , - id IPC_SET msg_perm.uid, msg_perm.gid, msg_perm.mode (9 msg_perm) mgr_qbytes , IPC_RMID - id sgget ______________________________ #include #include #include msgget(key,flag) key_t key; int flag; msgget , key. key , - (IPC_PRIVATE), . flag (IPC_CREAT), , - (IPC_EXCL). , - , msgget . sgsnd msgrcv ______________________________ #include #include #include msgsnd(id,msgp,size,flag) 407 int id,size,flag; struct msgbuf *msgp; msgrcv(id,msgp,size,type,flag) int id,size,type,flag; struct msgbuf *msgmp; msgsnd (size) msgp id. msgbuf - : struct msgbuf { long mtype; char mtext[]; }; flag IPC_NOWAIT , msgsnd - , . IPC_NOWAIT - , msgsnd . msgrcv id. type , , ; , ; , , , type. size , . flag MSG_NOERROR, , - , size, - . , - . flag IPC_NOWAIT , msgrcv , , - type , . - , . msgrcv ( ). i ______________________________ nice(increment) int increment; nice , - , increment. nice - . pe ______________________________ #include open(filename,flag,mode) char *filename; int flag,mode; open - 408 flag. flag ( ): O_RDONLY O_WRONLY O_RDWR O_NDELAY - , , - ; - , ( , O_WRONLY ), - O_APPEND O_CREAT , ; - (mode) , creat; , - O_TRUNC 0 O_EXCL O_CREAT , ; " " open . aus ______________________________ pause() pause . ip ______________________________ pipe(fildes) int fildes[2]; pipe (, fildes[0] fildes[1]) . ; . lock ______________________________ #include plock(op) int op; plock - op: 409 PROCLOCK TXTLOCK DATLOCK UNLOCK rofil ______________________________ profil(buf,size,offset,scale) char *buf; int size,offset,scale; profil . buf , , . size buf, offset - - , scale - . tra ______________________________ ptrace(cmd,pid,addr,data) int cmd,pid,addr,data; ptrace , pid, cmd: 0 ( ) 1,2 , addr - pid 3 , - addr 4,5 addr - 6 addr 7 - 8 - 9 - - - read ______________________________ read(fildes,buf,size) int fildes; char *buf; int size; read fildes - buf size . - . open O_NDELAY, read 410 . semctl ______________________________ #include #include #include semctl(id,num,cmd,arg) int id,num,cmd; union semun { int val; struct semid_ds *buf; ushort *array; } arg; semctl cmd id. GETVAL , - num SETVAL , - num, arg.val GETPID , - semop - , num GETNCNT , , GETZCNT , , GETALL arg.array SETALL arg.array IPC_STAT - id arg.buf IPC_SET sem_perm.uid, sem_perm.gid sem_perm.mode ( 9 sem_perm) arg.buf IPC_RMID , id, num . semid_ds : struct semid_ds { struct ipc_perm sem_perm; /* , - - */ int * pad; /* - */ ushort sem_nsems; /* - */ time_t sem_otime; /* */ 411 time_t sem_ctime; /* */ }; ipc_perm , msgctl. semget ______________________________ #include #include #include semget(key,nsems,flag) key_t key; int nsems,flag; semget , key. key flag , msgget. se ______________________________ semop(id,ops,num) int id,num; struct sembuf **ops; semop , ops, , id. num - , ops. sembuf - : struct sembuf { short sem_num; /* */ short sem_op; /* */ short sem_flg; /* */ }; sem_num , - , sem_flg - . sem_op : sem_op >= 0, sem_op; , , sem_op 0, - ; , - , - sem_flg IPC_NOWAIT, semop , . SEM_UNDO, 412 (sem_op ). , . semop . setpgr ______________________________ setpgrp() setpgrp , , - . setuid ______________________________ setuid(uid) int uid; setgid(gid) int gid; setuid - . , . , , uid, setuid - . , uid , setuid-, exec. setgid . shmctl ______________________________ #include #include #include shmctl(id,cmd,buf) int id,cmd; struct shmid_ds *buf; shmctl - , id. shmid_ds : struct shmid_ds { struct ipc_perm shm_perm; /* , - */ int shm_segsz; /* */ int * pad1; /* - */ ushort shm_lpid; /* - , 413 */ ushort shm_cpid; /* - - */ ushort shm_nattch; /* - */ short pad2; /* - */ time_t shm_atime; /* */ time_t shm_dtime; /* */ time_t shm_ctime; /* - */ }; : IPC_STAT buf - , id IPC_SET shm_perm.uid, shm_perm.gid shm_perm.mode (9 - ) - buf IPC_RMID , id shmget ______________________________ #include #include #include shmget(key,size,flag) key_t key; int size,flag; shmget . size . key flag , msgget. sh ______________________________ #include #include #include shmat(id,addr,flag) int id,flag; char *addr; shmdt(addr) char *addr; 414 shmat , id, . addr , - . , addr . flag SHM_RND, . shmat , . shmdt , - addr. signal ______________________________ #include signal(sig,function) int sig; void (*func)(); signal . sig : SIGHUP "" SIGINT SIGQUIT SIGILL SIGTRAP , SIGIOT IOT SIGEMT EMT SIGFPE SIGKILL SIGBUS SIGSEGV SIGSYS SIGPIPE SIGALRM SIGTERM SIGUSR1 , SIGUSR2 , SIGCLD SIGPWR function : SIG_DFL . - , - SIGPWR SIGCLD. SIGQUIT, SIGILL, SIGTRAP, SIGIOT, SIGEMT, SIGFPE, SIGBUS, SIGSEGV SIGSYS, "core", SIG_IGN . - . , - SIGILL, SIGTRAP SIGPWR, - SIG_DFL. SIGKILL 415 .te1 stat ______________________________ stat(filename,statbuf) char *filename; struct stat *statbuf; fstat(fd,statbuf) int fd; struct stat *statbuf; stat () - . fstat , - fd. statbuf : struct stat { dev_t st_dev; /* , - */ ino_t st_ino; /* */ ushort st_mode; /* (. mknod) (. chmod) */ short st_nlink; /* , */ ushort st_uid; /* */ ushort st_gid; /* */ dev_t st_rdev; /* */ off_t st_size; /* */ time_t st_atime; /* */ time_t st_mtime; /* */ time_t st_ctime; /* */ }; sti ______________________________ stime(tptr) long *tptr; stime , tptr. 00:00:00 1 1970 . sy ______________________________ sync() sync (- ) . ti ______________________________ time(tloc) 416 long *tloc; time 00:00:00 1 1970 . times ______________________________ #include #include times(tbuf) struct tms *tbuf; times , , tbuf : struct tms { time_t tms_utime; /* - */ time_t tms_stime; /* - */ time_t tms_cutime; /* tms_utime tms_cutime */ time_t tms_sutime; /* tms_stime tms_sutime */ }; limit ______________________________ ulimit(cmd,limit) int cmd; long limit; ulimit - cmd: 1 ( 512 ), 2 - limit 3 ( ) ask ______________________________ umask(mask) int mask; umask , (mask), . - , mask, - . 417 ount ______________________________ umount(specialfile) char *specialfile umount , - specialfile. a ______________________________ #include uname(name) struct utsname *name; uname , - : struct utsname { char sysname[9]; /* */ char nodename[9]; /* */ char release[9]; /* */ char version[9]; /* */ char machine[9]; /*