0% found this document useful (0 votes)
60 views10 pages

Prototipos de Algunos System Calls de Unix

This document summarizes several Unix system calls related to processes, signals, file I/O, directories, networking, inter-process communication, and sockets. It describes functions like fork(), execve(), wait(), kill(), open(), close(), read(), write(), socket(), bind(), listen(), accept(), and connect(). It also provides details on data structures like sigaction and sockaddr_in that are used with some of these system calls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views10 pages

Prototipos de Algunos System Calls de Unix

This document summarizes several Unix system calls related to processes, signals, file I/O, directories, networking, inter-process communication, and sockets. It describes functions like fork(), execve(), wait(), kill(), open(), close(), read(), write(), socket(), bind(), listen(), accept(), and connect(). It also provides details on data structures like sigaction and sockaddr_in that are used with some of these system calls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Prototipos de algunos system calls de Unix

pid_t fork(void);
int execve(const char *path, char *const argv[], char *const envp[]);
void exit(int status);
pid_t wait(int *stat_loc);
pid_t waitpid(pid_t pid, int *stat_loc, int options);
The options parameter contains the itwise !" of an# of the following options$ The
%&!'(&) option is used to indicate that the call should not lock if there are no
processes that wish to report status$ *f the %+&T"(,-. option is set, children of
the current process that are stopped due to a /*)TT*&, /*)TT!+, /*)T/T0, or
/*)/T!0 signal also have their status reported$
The following macros ma# e used to test the manner of exit of the process$ !ne
of the first three macros will evaluate to a non12ero (true) value3
%*4-5*T-.(status)3 True if the process terminated normall# # a call to _exit(6) or
exit(7)$
%*4/*)&(8-.(status)3 True if the process terminated due to receipt of a signal$
%*4/T!00-.(status)3 True if the process has not terminated, ut has stopped and
can e restarted$ This macro can e true onl# if the wait call specified the
%+&T"(,-. option or if the child process is eing traced (see ptrace(6))$
.epending on the values of those macros, the following macros produce the
remaining status information aout the child process3
%-5*T/T(T+/(status)3 *f %*4-5*T-.(status) is true, evaluates to the low1order 9
its of the argument passed to _exit(6) or exit(7) # the child$
%T-":/*)(status)3 *f %*4/*)&(8-.(status) is true, evaluates to the numer of
the signal that caused the termination of the process$
%,!"-.+:0(status)3 *f %*4/*)&(8-.(status) is true, evaluates as true if the
termination of the process was accompanied # the creation of a core file
containing an image of the process when the signal was received$
%/T!0/*)(status)3 *f %*4/T!00-.(status) is true, evaluates to the numer of the
signal that caused the process to stop$
pid_t getpid(void);
pid_t getppid(void);
pid_t getpgid(pid_t pid);
pid_t getpgrp(void);
int setpgid(pid_t pid, pid_t pgid);
pid_t setpgrp(void);
pid_t setsid(void);
int kill(pid_t pid, int sig);
struct sigaction ;
union ;
void (*__sa_handler)(int);
void (*__sa_sigaction)(int, struct __siginfo *, void *);
< __sigaction_u; =* signal handler *=
int sa_flags; =* see signal options elow *=
sigset_t sa_mask; =* signal mask to appl# *=
<;
>define sa_handler __sigaction_u$__sa_handler
>define sa_sigaction __sigaction_u$__sa_sigaction
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact);
sa_flags3
/(_"-/-T'(&.3 *f this it is set, the handler is reset ack to /*)_.48 at the
moment the signal is delivered$
/(_/*)*&4!3 *f this it is set, the handler function is assumed to e pointed to #
the sa_sigaction memer of struct sigaction and should match the protot#pe shown
aove$ This it should not e set when assigning /*)_.48 or /*)_*)&$
t#pedef void (*sig_t) (int);
sig_t signal(int sig, sig_t func);
int open(const char *path, int oflag [, mode_t mode]);
int creat(const char *path, mode_t mode);
int dup(int fildes);
int dup6(int fildes, int fildes6);
int pipe(int fildes[6]);
int close(int fildes);
ssi2e_t read(int fildes, void *uf, si2e_t n#te);
ssi2e_t write(int fildes, const void *uf, si2e_t n#te);
off_t lseek(int fildes, off_t offset, int whence);
int rename(const char *old, const char *new);
int link(const char *path?, const char *path6);
int unlink(const char *path);
int mknod(const char *path, mode_t mode, dev_t dev);
int mkfifo(const char *path, mode_t mode);
void s#nc(void);
int fs#nc(int fildes);
struct stat ;
dev_t st_dev; =* device inode resides on *=
ino_t st_ino; =* inode@s numer *=
mode_t st_mode; =* inode protection mode *=
nlink_t st_nlink; =* numer or hard links to the file *=
uid_t st_uid; =* user1id of owner *=
gid_t st_gid; =* group1id of owner *=
dev_t st_rdev; =* device t#pe, for special file inode *=
struct timespec st_atimespec; =* time of last access *=
struct timespec st_mtimespec; =* time of last data modification *=
struct timespec st_ctimespec; =* time of last file status change *=
off_t st_si2e; =* file si2e, in #tes *=
Auad_t st_locks; =* locks allocated for file *=
u_long st_lksi2e; =* optimal file s#s *=! ops locksi2e *=
u_long st_flags; =* user defined flags for file *=
u_long st_gen; =* file generation numer *=
<;
int stat(const char *path, struct stat *uf);
int fstat(int fildes, struct stat *uf);
int access(const char *path, int amode);
int fcntl(int fildes, int cmd, $$$);
cmd3
4_/-T4.3 /et the close1on1exec flag associated with fildes to the low order it of
arg (B or ? as aove)$
struct flock ;
off_t l_start; =* starting offset *=
off_t l_len; =* len C B means until end of file *=
pid_t l_pid; =* lock owner *=
short l_t#pe; =* lock t#pe3 read=write, etc$ *=
short l_whence; =* t#pe of l_start *=
<;
The commands availale for advisor# record locking are as follows3
4_)-T8D3 )et the first lock that locks the lock description pointed to # the third
argument, arg, taken as a pointer to a struct flock (see aove)$ The information
retrieved overwrites the information passed to fcntl in the flock structure$ *f no lock
is found that would prevent this lock from eing created, the structure is left
unchanged # this function call except for the lock t#pe which is set to 4_+&8,D$
4_/-T8D3 /et or clear a file segment lock according to the lock description pointed
to # the third argument, arg, taken as a pointer to a struct flock (see aove)$
4_/-T8D is used to estalish shared (or read) locks (4_".8,D) or exclusive (or
write) locks, (4_%"8,D), as well as remove either t#pe of lock (4_+&8,D)$ *f a
shared or exclusive lock cannot e set, fcntl returns immediatel# with -(,,-/$
4_/-T8D%3 This command is the same as 4_/-T8D except that if a shared or
exclusive lock is locked # other locks, the process waits until the reAuest can e
satisfied$ *f a signal that is to e caught is received while fcntl is waiting for a
region, the fcntl will e interrupted if the signal handler has not specified the
/(_"-/T("T (see sigaction(6))$
int chdir(const char *path);
int chroot(const char *dirname);
.*" *opendir(const char *dirname);
int closedir(.*" *dirp);
struct dirent *readdir(.*" *dirp);
void rewinddir(.*" *dirp);
void seekdir(.*" *dirp, long loc);
long telldir(.*" *dirp);
uid_t getuid(void);
uid_t geteuid(void);
gid_t getgid(void);
gid_t getegid(void);
int setuid(uid_t uid);
int seteuid(uid_t euid);
int setgid(gid_t gid);
int setegid(gid_t egid);
int semget(ke#_t ke#, int nsems, int semflg);
ke#3 *0,_0"*E(T-
semflg3 *0,_,"-(T, *0,_-5,8, modo
struct semuf ;
unsigned short sem_num; =* semaphore numer *=
short sem_op; =* semaphore operation *=
short sem_flg; =* operation flags *=
<;
flg3 *0,_&!%(*T, /-:_+&.!
int semop(int semid, struct semuf *sops, unsigned nsops);
int semtimedop(int semid, struct semuf *sops, unsigned nsops, struct timespec
*timeout);
int semctl(int semid, int semnum, int cmd, $$$);
cmd3 *0,_":*., )-TE(8, /-TE(8
int msgget(ke#_t ke#, int msgflg);
ke#3 *0,_0"*E(T-
msgflg3 *0,_,"-(T, *0,_-5,8, modo
struct msguf ;
long mt#pe; =* message t#pe, must e F B *=
char mtext[?]; =* message data *=
<;
int msgsnd(int msAid, struct msguf *msgp, si2e_t msgs2, int msgflg);
ssi2e_t msgrcv(int msAid, struct msguf *msgp, si2e_t msgs2, long msgt#p, int
msgflg);
msgflg3 *0,_&!%(*T
int msgctl(int msAid, int cmd, struct msAid_ds *uf);
cmd3 *0,_":*.
int shmget(ke#_t ke#, si2e_t si2e, int shmflg);
ke#3 *0,_0"*E(T-
msgflg3 *0,_,"-(T, *0,_-5,8, modo
void *shmat(int shmid, const void *shmaddr, int shmflg);
int shmdt(const void *shmaddr);
shmflg3 /':_".!&8G
int shmctl(int shmid, int cmd, struct shmid_ds *uf);
cmd3 *0,_":*.
sem_t *sem_open(const char *name, int oflag [, mode_t mode, unsigned int
value]);
oflag3 !_,"-(T, !_-5,8, modo
int sem_close(sem_t *sem);
int sem_unlink(const char *name);
int sem_post(sem_t *sem);
int sem_tr#wait(sem_t *sem);
int sem_wait(sem_t *sem);
int sem_timedwait(sem_t *sem, const struct timespec *as_timeout);
mAd_t mA_open(const char *name, int oflag [, mode_t mode]);
oflag3 !_,"-(T, !_-5,8, !_&!&H8!,D, modo
int mA_send(mAd_t mAdes, const char *msg_ptr, si2e_t msg_len, unsigned
msg_prio);
int mA_timedsend(mAd_t mAdes, const char *msg_ptr, si2e_t msg_len, unsigned
msg_prio, const struct timespec *as_timeout);
ssi2e_t mA_receive(mAd_t mAdes, char *msg_ptr, si2e_t msg_len,unsigned
*msg_prio);
ssi2e_t mA_timedreceive(mAd_t mAdes, char *msg_ptr, si2e_t msg_len, unsigned
*msg_prio, const struct timespec *as_timeout);
int mA_getattr(mAd_t mAdes, struct mA_attr *mAstat);
int mA_setattr(mAd_t mAdes, const struct mA_attr *mAstat, struct mA_attr
*omAstat);
int shm_open(const char *name [, mode_t mode]);
int shm_unlink(const char *name);
void *mmap(void *addr, si2e_t len, int prot, int flags, int fildes, off_t offset);
prot3 0"!T_-5-,, 0"!T_"-(., 0"!T_%"*T-
flags3 :(0_(&!&, :(0_4*8-, :(0_4*5-., :(0_0"*E(T-, :(0_/'("-.,
:(0_&!,(,'-
int ms#nc(void *addr, si2e_t len, int flags);
int munmap(void *addr, si2e_t len);
int socket(int domain, int t#pe, int protocol);
domain3 (4_+&*5, (4_*&-T
t#pe3 /!,D_/T"-(:, /!,D_.)"(:
struct sockaddr_in ;
short sin_famil#; == (4_*&-T
unsigned short sin_port; == e$g$ htons(7IJB)
struct in_addr sin_addr; == see struct in_addr, elow
char sin_2ero[9]; == 2ero this if #ou want to
<;
struct in_addr ;
unsigned long s_addr; == load with inet_pton()
<;
struct sockaddr_un ;
unsigned short sun_famil#; == (4_+&*5
char sun_path[?B9];
<;
int ind(int socket, const struct sockaddr *address, socklen_t address_len);
int listen(int socket, int acklog);
int accept(int socket, struct sockaddr *address, socklen_t *address_len);
int connect(int socket, const struct sockaddr *address, socklen_t address_len);
ssi2e_t recv(int socket, void *uffer, si2e_t length, int flags);
ssi2e_t recvfrom(int socket, void *uffer, si2e_t length, int flags, struct sockaddr
*address, socklen_t *address_len);
flags3 :/)_!!H, :/)_0--D, :/)_%(*T(88
ssi2e_t send(int socket, const void *uffer, si2e_t length, int flags);
ssi2e_t sendto(int socket, const void *uffer, si2e_t length, int flags, const struct
sockaddr *dest_addr, socklen_t dest_len);
flags3 :/)_!!H, :/)_.!&T"!+T-
int getsockname(int socket, struct sockaddr *address, socklen_t *address_len);
int getpeername(int socket, struct sockaddr *address, socklen_t *address_len);
struct hostent ;
char *h_name; =* official name of host *=
char **h_aliases; =* alias list *=
int h_addrt#pe; =* host address t#pe *=
int h_length; =* length of address *=
char **h_addr_list; =* list of addresses from name server *=
<;

struct hostent *gethost#name(const char *name);
struct hostent *gethost#addr(const void *addr, socklen_t len, int t#pe);
T'"-(. "!+T*&-/
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void
*(*start_routine)(void *), void *arg)3 ,reates a new thread of execution$
int pthread_detach(pthread_t thread)3 :arks a thread for deletion$
int pthread_eAual(pthread_t t?, pthread_t t6)3 ,ompares two thread *.s$
void pthread_exit(void *value_ptr)3 Terminates the calling thread$
int pthread_Koin(pthread_t thread, void **value_ptr)3 ,auses the calling thread to
wait for the termination of the specified thread$
int pthread_cancel(pthread_t thread)3 ,ancels execution of a thread$
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))3 ,alls
an initiali2ation routine once$
pthread_t pthread_self(void)3 "eturns the thread *. of the calling thread$
int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))3
"egisters handlers to e called efore and after fork()
(TT"*H+T- !HL-,T "!+T*&-/
int pthread_attr_destro#(pthread_attr_t *attr)3 .estro# a thread attriutes oKect$
int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched)3 )et
the inherit scheduling attriute from a thread attriutes oKect$
int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param
*param)3 )et the scheduling parameter attriute from a thread attriutes oKect$
int pthread_attr_getschedpolic#(const pthread_attr_t *attr, int *polic#)3 )et the
scheduling polic# attriute from a thread attriutes oKect$
int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope)3 )et
the contention scope attriute from a thread attriutes oKect$
int pthread_attr_getstacksi2e(const pthread_attr_t *attr, si2e_t *stacksi2e)3 )et the
stack si2e attriute from a thread attriutes oKect$
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)3 )et
the stack address attriute from a thread attriutes oKect$
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)3 )et
the detach state attriute from a thread attriutes oKect$
int pthread_attr_init(pthread_attr_t *attr)3 *nitiali2e a thread attriutes oKect with
default values$
int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched)3 /et the
inherit scheduling attriute in a thread attriutes oKect$
int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param
*param)3 /et the scheduling parameter attriute in a thread attriutes oKect$
int pthread_attr_setschedpolic#(pthread_attr_t *attr, int polic#)3 /et the scheduling
polic# attriute in a thread attriutes oKect$
int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope)3 /et the
contention scope attriute in a thread attriutes oKect$
int pthread_attr_setstacksi2e(pthread_attr_t *attr, si2e_t stacksi2e)3 /et the stack
si2e attriute in a thread attriutes oKect$
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)3 /et the stack
address attriute in a thread attriutes oKect$
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)3 /et the
detach state in a thread attriutes oKect$
:+T-5 "!+T*&-/
int pthread_mutexattr_destro#(pthread_mutexattr_t *attr)3 .estro# a mutex
attriutes oKect$
int pthread_mutexattr_init(pthread_mutexattr_t *attr)3 *nitiali2e a mutex attriutes
oKect with default values$
int pthread_mutex_destro#(pthread_mutex_t *mutex)3 .estro# a mutex$
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t
*attr)3 *nitiali2e a mutex with specified attriutes$
int pthread_mutex_lock(pthread_mutex_t *mutex)3 8ock a mutex and lock until it
ecomes availale$
int pthread_mutex_tr#lock(pthread_mutex_t *mutex)3 Tr# to lock a mutex, ut
don@t lock if the mutex is locked # another thread, including the current thread$
int pthread_mutex_unlock(pthread_mutex_t *mutex)3 +nlock a mutex$
,!&.*T*!& E("*(H8- "!+T*&-/
int pthread_condattr_init(pthread_condattr_t *attr)3 *nitiali2e a condition variale
attriutes oKect with default values$
int pthread_condattr_destro#(pthread_condattr_t *attr)3 .estro# a condition
variale attriutes oKect$
int pthread_cond_roadcast(pthread_cond_t *cond)3 +nlock all threads currentl#
locked on the specified condition variale$
int pthread_cond_destro#(pthread_cond_t *cond)3 .estro# a condition variale$
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)3
*nitiali2e a condition variale with specified attriutes$
int pthread_cond_signal(pthread_cond_t *cond)3 +nlock at least one of the
threads locked on the specified condition variale$
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *astime)3 %ait no longer than the specified time for a
condition and lock the specified mutex$
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *mutex)3 %ait for a
condition and lock the specified mutex$
"-(.=%"*T- 8!,D "!+T*&-/
int pthread_rwlock_destro#(pthread_rwlock_t *lock)3 .estro# a read=write lock
oKect$
int pthread_rwlock_init(pthread_rwlock_t *lock, const pthread_rwlockattr_t *attr)3
*nitiali2e a read=write lock oKect$
int pthread_rwlock_rdlock(pthread_rwlock_t *lock)3 8ock a read=write lock for
reading, locking until the lock can e acAuired$
int pthread_rwlock_tr#rdlock(pthread_rwlock_t *lock)3 (ttempt to lock a read=write
lock for reading, without locking if the lock is unavailale$
int pthread_rwlock_tr#wrlock(pthread_rwlock_t *lock)3 (ttempt to lock a read=write
lock for writing, without locking if the lock is unavailale$
int pthread_rwlock_unlock(pthread_rwlock_t *lock)3 +nlock a read=write lock$
int pthread_rwlock_wrlock(pthread_rwlock_t *lock)$ 8ock a read=write lock for
writing, locking until the lock can e acAuired$
int pthread_rwlockattr_destro#(pthread_rwlockattr_t *attr)3 .estro# a read=write
lock attriute oKect$
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared)3
"etrieve the process shared setting for the read=write lock attriute oKect$
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)3 *nitiali2e a read=write lock
attriute oKect$
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared)3 /et the
process shared setting for the read=write lock attriute oKect$
0-"1T'"-(. ,!&T-5T "!+T*&-/
int pthread_ke#_create(pthread_ke#_t *ke#, void (*routine)(void *))3 ,reate a
thread1specific data ke#$
int pthread_ke#_delete(pthread_ke#_t ke#)3 .elete a thread1specific data ke#$
void * pthread_getspecific(pthread_ke#_t ke#)3 )et the thread1specific value for
the specified ke#$
int pthread_setspecific(pthread_ke#_t ke#, const void *value_ptr)$ /et the thread1
specific value for the specified ke#$
,8-(&+0 "!+T*&-/
void pthread_cleanup_pop(int execute)3 "emove the routine at the top of the
calling thread@s cancellation cleanup stack and optionall# invoke it$
void pthread_cleanup_push(void (*routine)(void *), void *routine_arg)3 0ush the
specified cancellation cleanup handler onto the calling thread@s cancellation stack$

You might also like