0% found this document useful (0 votes)
4 views2 pages

System Calls

Uploaded by

s308276
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

System Calls

Uploaded by

s308276
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

OPERATING SYSTEMS - 04JEZOQ – Laurea Magistrale in Ingegneria Elettronica – Politecnico di Torino

#include <unistd.h.h> int execl(const char *pathname, const char int pthread_join(pthread_t thread, void performs the control operation specified by
#include <sys/types.h> *arg0, …) **retval) cmd on the shared memory segment whose
int fork(void) int execv(const char *pathname, char *const waits for the thread specified by thread to identifier is given in shmid.
creates a child process argv []) terminate. If that thread has already
the return code is zero for the new (child) int execlp(const char *filename, const char terminated, then pthread_join() returns Typical usage: shmctl(shmid, IPC_RMID, 0);
process *arg0, . . .) immediately. Remove shared memory segment
int getpid() int execvp(const char *filename, char *const On success, it returns 0; on error, it returns
returns the process ID of the calling process. argv[]) an error number. int shmdt(const void *shmaddr)
int getppid() int execle(const char *pathname, const char detaches the shared memory segment
returns the process ID of the parent of the *arg0, … , char *const envp[] ) #include <sys/shm.h> located at the address specified by shmaddr
calling process. int execve(const char *pathname, char from the address space of the calling process.
void exit(int status) *const argv[], char *const envp[]) int shmget(key_t key, int size, int shmflg)
causes normal process termination and the #include <sys/msg.h>
value of status & 0377 is returned to the The exec() family of functions replaces the returns the identifier of the shared memory
parent current process image with a new process segment associated with the value of the int msgget(key_t key, int flag)
unsigned int sleep(unsigned int seconds) image argument key. creates a message queue
makes the calling thread sleep until seconds The pathname argument specifies the path
seconds have elapsed or a signal arrives name of the file to execute as the new key is an integer that specifies which key is an integer that specifies the queue key
which is not ignored process image. segment to create (IPC_PRIVATE reserved for flag indicates creation conditions and access
Arguments arg0 through argn are a list of launching process) permissions. It is the bitwise or of flag values.
#include <sys/types.h> pointers to arguments to be passed to the size determines the size in bytes of the It returns the message queue identifier.
#include <sys/wait.h> new process image shared memory segment Typical usage:
pid_t wait(int *status) shmflg is used to indicate segment creation msgget(100, 0660 | IPC_CREATE);
suspends execution of the calling process #include <pthread.h> conditions and access permissions (it is the Creates queue with write and read privileges
until one of its children terminates. int pthread_create(pthread_t *thread, const bitwise or of flag values) for user and group
on success, it returns the process ID of the pthread_attr_t *attr, void *(*start_routine)
terminated child; (void *), void *arg) void *shmat(int shmid, const void int msgsnd(int msqid, const void *ptr, size_t
on error, ‐1 is returned *shmaddr, int shmflg) nbytes, int flag);
pid_t waitpid(pid_t pid, int *status, int starts a new thread in the calling process msqid corresponds to the message queue
options) thread: a unique identifier for the new thread identifier
attaches the shared memory segment
suspends execution of the calling process returned by the subroutine. ptr argument points to a data structure that
identified by shmid to the address space of
until a child specified by pid argument has attr: it specifies a thread attributes object, or contains the integer message type and the
the calling process.
changed state. NULL for the default values. message data
By default (options=0), waitpid() waits only start_routine: the routine that the thread will A message is composed by the following
shmid is a valid shared memory identifier
for terminated children, but this behavior is execute once it is created struct type
modifiable via the options argument arg: A single argument that may be passed to struct my_msg
typical usage:
on success, returns the process ID of the child start_routine {
shm = shmat(shmid, NULL, 0);
whose state has changed; pthread_id pthread_self(void) long int my_msg_type;
Assign the shared memory segment to a
on error, ‐1 is returned. return identifier of current thread char some_text[MAX_TEXT];
default location in process address space };
void pthread_exit(void *retval)
If status is not NULL, wait() and waitpid() terminates the calling thread and returns a A message is composed by a positive long
int shmctl(int shmid, int cmd, struct integer type field and a nbytes of the actual
store status information in the int to which it value via retval that (if the thread is joinable)
shmid_ds *buf) data bytes
points. is available to another thread in the same
process that calls pthread_join
OPERATING SYSTEMS - 04JEZOQ – Laurea Magistrale in Ingegneria Elettronica – Politecnico di Torino
int msgrcv(int msqid, void *msgp, size_t int unlink(const char *pathname) If pid equals ‐1, then sig is sent to every Sets the integer referenced by sval to the
msgsz, long msgtype, int msgflg) deletes the file pathname from the process for which the calling process has value of the semaphore sem
msqid corresponds to the message queue filesystem. permission to send signals, except for
identifier If that name was the last link to a file and no process 1 (init) #include <pthread.h>
msgp argument points to a user‐defined processes have the file open the file is sighandler_t signal(int signum, sighandler_t int pthread_mutex_init( pthread_mutex_t
buffer for holding the message to be deleted and the space it was using is made handler); *mutex, const pthread_mutexattr_t *attr);
retrieved (the format is the same adopted for available for reuse. installs a new signal handler for the signal mutex lock creation
the sender) with number signum. The signal handler is Typical usage:
msgsz specifies the actual size of the int open(const char *pathname, int flags) set to handler which may be a user specified pthread_mutex_init(&mut, NULL);
message text opens a file. function int pthread_mutex_lock (pthread_mutex_t
msgtype can be used by the receiver for Given a pathname for a file, open() returns a unsigned int alarm(unsigned int seconds); *mutex)
message selection file descriptor, a nonnegative integer for use causes the system to generate a SIGALRM Locking a mutex lock: if the lock is already
If successful, it returns the number of bytes in subsequent system calls (read(), write(), signal for the process after the number of locked, then the calling thread is blocked; if
in the text of the message. etc.). real‐time seconds specified by seconds have the lock is not locked, then the calling thread
If unsuccessful, it returns ‐1. The file descriptor returned by a successful elapsed acquires it
call will be the lowest‐numbered file int pause(void); int pthread_mutex_trylock
int msgctl(int msqid, int cmd, struct descriptor not currently open for the process. causes the invoking process to sleep until a (pthread_mutex_t *mutex)
msqid_ds *buf) ssize_t read(int fildes, void *buf, size_t signal is received that either terminates it or Just checks the mutex lock.
modifies the properties of the queue nbyte) causes it to call a signal‐catching function. It returns 0 on success, EBUSY if the lock is
msqid corresponds to the message q ueue it shall attempt to read nbyte bytes from the locked, an error code otherwise
identifier file associated with the open file descriptor, #include <semaphore.h> int pthread_mutex_unlock
typical usage: fildes, into the buffer pointed to by buf. All semaphore functions: (pthread_mutex_t *mutex)
msgctl(msgid, IPC_RMID, 0); Upon successful completion, it returns a non‐ if successful, return 0; releases a mutex lock
Removes queue negative integer indicating the number of otherwise they return ‐1 int pthread_mutex_destroy(
bytes actually read. Otherwise, it returns ‐1. int sem_init (sem_t *sem, int pshared, pthread_mutex_t *mutex)
int pipe( int fd[2] ) ssize_t write(int fd, const void *buf, size_t unsigned int value); destroys the initialized unlocked mutex.
creates an unnamed pipe and returns two file count) Initializes semaphore sem to value parameter
descriptors: writes up to count bytes from the buffer pshared is the type of semaphore; int pthread_cond_init( pthread_cond_t
the descriptor associated with the “read” end pointed buf to the file referred to by the file if 0, then semaphore is local to the current *cond, const pthread_condattr_t *attr);
of the pipe is stored in fd[0] descriptor fd. process Creating a condition variable
the descriptor associated with the “write” int close(int fildes); else the semaphore may be shared between cond: the created condition variable
end of the pipe is stored in fd[1] deallocates the file descriptor indicated by processes (e.g., the process that initializes it attr: attributes (default = NULL)
Return value: If the kernel cannot allocate fildes. and its child). returns 0 on success, an error code otherwise
enough space for a new pipe, it returns a Upon successful completion, 0 is returned. int sem_destroy (sem_t *sem); int pthread_cond_wait(pthread_cond_t
value of ‐1; otherwise, it returns a value of 0. Otherwise, ‐1 is returned removes semaphores sem from the system *cond, pthread_mutex_t *mutex);
int sem_wait (sem_t *sem); Waiting on a condition variable cond with the
int mkfifo(const char *path, mode_t mode); #include <signal.h> wait operation on semaphore sem associated mutex
creates a named pipe (FIFO) int sem_post (sem_t *sem); returns 0 on success, an error code otherwise
path corresponds to the name of the pipe. int kill(pid_t pid, int sig) signal operation on semaphore sem int pthread_cond_signal( pthread_cond_t
mode corresponds to the permission mode send signal sig to a process pid int sem_try (sem_t *sem); *cond)
flags. If pid equals 0, then sig is sent to every sem_trywait is similar to sem_wait except Signaling a condition variable cond
process in the process group of the current instead of blocking on 0, it returns –1 returns 0 on success, an error code otherwise
process. int sem_getvalue (sem_t *sem, int *sval);

You might also like