CSCI 4500/8506 Operating Systems Some UNIX System Calls, Library, and PThreads Functions

Size: px
Start display at page:

Download "CSCI 4500/8506 Operating Systems Some UNIX System Calls, Library, and PThreads Functions"

Transcription

1 CSCI 4500/8506 Operating Systems Some UNIX System Calls, Library, and PThreads Functions Described below is a subset of UNIX system calls, library functions, and Pthreads (that is, POSIX Threads) functions. It is not meant to be comprehensive, nor is it meant to describe every possible parameter and result in complete detail. It should, however, prove useful in preparing solutions to many of the assignments for the course. The form for the entries is similar to that used in the UNIX manual pages, but there is no explicit division of the information into sections. Instead most entries provide a synopsis of the item (including the header file, or files, that should be included), a brief description of its purpose, and an indication of the returned value and the most common errors that might be encountered. The entries are given in alphabetical order. Each of the Pthreads entries begins with pthread_. access int access (const char *path, int mode) alarm brk access checks to see if the file named by path can be accessed as indicated by mode, which is the bitwise-or of R_OK, W_OK, and/or X_OK (for read, write, and execute/search permission, respectively) or F_OK (for testing the file s existence only). 0 is returned if the specified access mode is permitted. access returns 1 and sets the global variable errno if an error is encountered. unsigned alarm (unsigned secs) alarm sets a timer to deliver the SIGALRM signal to the calling process after secs seconds. The call supersedes any previous unexpired alarm in effect. Calling alarm with secs equal 0 cancels any pending alarm. alarm returns the amount of time, in seconds, remaining on the timer associated with a previous alarm call. If no alarm is currently set, the returned value is 0. This function is usually marked as obsolete, because the more modern setitimer system call can be used to achieve the a similar function. It can still be used, however. int brk (void *addr) brk changes the address associated with the end of the data segment for the calling process. This address, specified by the addr argument, is called the program break. Increasing the address causes memory to be allocated to the process, and decreasing the address deallocated memory. brk returns 0 on success. Applications rarely use brk directly, and instead depend on library mechanisms (like malloc in C and new in C++) to manage dynamically allocated memory. brk returns 1 and sets the global variable errno if an error is encountered.

2 chdir int chdir (const char *path) chdir changes the path to the working directory for the calling process to path, which must be the pathname of a directory. The working directory is used as the starting point for path searches of pathnames not beginning with a slash. chdir returns 0 on success. chdir returns 1 and sets the global variable errno if an error is encountered. chmod #include <sys/types.h> #include <sys/stat.h> int chmod (const char *path, mode_t mode) chmod changes the mode of the existing file at path to mode. Only the owner of the file or the super-user can change the mode of a file. The mode can be specified symbolically (see the full documentation for all the names that can be used), or specified as a numeric argument, for which the 12 low-order bits are significant. The low-order 9 bits are treated as 3 groups of 3 bits each giving the read, write, and execute/search permission for the owner/user, the group owner, and all others, respectively. Thus 0742 would specify read/write/execute for the owner, read for the group, and write for all others. The next higher 3 bits specify the ser user ID, set group ID, and the sticky bit, respectively. See the full documentation for details on these bits. chmod returns 0 on success. chmod returns 1 and sets the global variable errno if an error is encountered. chown int chown (const char *path, uid_t owner, gid_t group) chown changes the owner and group associated with the file at path to owner and group, respectively. The current owner of the file can change the group ownership to that of a group of which he or she is a member. But only the super-user can change the owner of an existing file. chown returns 0 on success. chown returns 1 and sets the global variable errno if an error is encountered. chroot int chroot (const char *dirname) chroot causes the directory named by dirname to become the root directory that is, the starting point for path searches of pathnames beginning with '/'. chroot returns 0 on success. Its use is restricted to the super-user. chroot returns 1 and sets the global variable errno if an error is encountered.

3 close creat dup dup2 int close (int fd) close deletes one reference to the file that is accessed through the file descriptor fd. If this is the last reference to that instance of an open file, then the file pointer s value is also lost. Close returns 0 on success. All open files are closed when a process terminates. close returns 1 and sets the global variable errno if an error is encountered. #include <fcntl.h> int creat (const char *path, mode_t mode) creat is an early system call used to create a new file with the name given by path, or truncate an existing file with that name to zero length, set the protection mode for the file, and open it for writing only. It yields the same effects as open(path, O_CREAT O_TRUNC O_WRONLY, mode); creat returns 1 and sets the global variable errno if an error is encountered. int dup (int fd) dup arranges for an additional file descriptor (which is indicated by the returned value) to reference the same file as that currently referenced by the file descriptor fd. The value returned will be the smallest unused file descriptor (that is, it does not correspond to any open file). The new file descriptor references the same instance of the open file that fd references. In particular, this means both the new and the old file descriptors share the same file pointer. dup returns 1 and sets the global variable errno if an error is encountered. int dup2 (int oldfd, int newfd) dup2 arranges for the file descriptor with the value newfd to reference the same file as that currently referenced by the file descriptor oldfd. Newfd references the same instance of the open file that oldfd references. In particular, this means both newfd and oldfd share the same file pointer. dup2 returns 0 on success. dup2 returns 1 and sets the global variable errno if an error is encountered. execve int execve (char *filename, char *argv[], char *envp) execve executes the program identified by filename, which must be either a binary executable file or an interpreter script (not covered here). The argv argument is a pointer to an array of character strings that is passed to the main function (at least for programs written in C) of the program. These strings effectively represent the items that would appear on the command line if the program had been invoked by a typical shell.

4 exit _exit fcntl fork The last entry in the array must be a null pointer, which allows determination of the number of arguments (which is provided as an int argument to the main function). The envp argument is also a pointer to an array of character strings (usually of the form "key=value") that is also passed to the main function of the program. execve does not return if it is successful, since all of the memory belonging to the program executing execve is replaced by the new program s memory content. Execve returns 1 and sets the global variable errno if an error is encountered. #include <stdlib.h> void exit (int status) exit is a library function in the standard C library that, as its last action, invokes the _exit system call, which then terminates the calling process. The exit function does a few things before calling _exit. In particular, it arranges for all of the standard input/output streams to be flushed and closed. It does not return to calling program. void _exit (int status) _exit closes any open file descriptors and terminates the calling process. Note that buffered output from open output streams (such as those used by the I/O libraries in highlevel languages) will not be flushed/written, so output may be lost. Additionally, any existing child processes of the calling process are made wards of the state and are inherited by the process with pid 1. Application programs almost always will more appropriately use the exit function rather than the _exit system call. #include <fcntl.h> int fcntl (int fd, int cmd,...) fcntl is used to effect actions on file descriptors other than things like read, write, and close. The file descriptor to be affected is identified by fd, and the command to be performed is specified by cmd. If cmd requires one or more operands, they are specified after the cmd argument. See the detailed documentation for more information on fcntl. int fork (void) fork creates an exact duplicate of the calling process, with the following exceptions. The new process (called the child ) has a unique process ID. The new process has a different parent process ID. The new process has its own copy of each of the parent s file descriptors. These descriptors reference the same underlying objects as the parent. For example, both the child and its parent share the same file pointer, so lseek in the child affects the file position used by the parent. (This isn t always true for all file descriptors; see the full description of fork for exceptions.)

5 fstat Fork effectively returns twice if it is successful, once in the parent and once in the child. In the parent, fork returns the process ID of the newly created child process. In the child, fork returns 0. Fork is frequently followed by a call to one of the exec family of system calls (e.g. execve) in the child process. Fork returns 1 in the parent and sets the global variable errno if an error is encountered. #include <sys/types.h> #include <sys/stat.h> int fstat (int fd, struct stat *sb) Fstat obtains information about the open file identified by fd. The sb argument is a pointer to a structure with at least the following components: st_dev st_ino st_mode st_nlink st_uid st_gid st_rdev st_size getgid pid_t getgid (void) device associated with the file s inode file s inode number on the device file s protection mode number of hard links to the file UID of the file s owner GID of the file s owner device type file size, in bytes getgid returns the real group ID of the calling process; there is no error return. The real group ID is that of the user who invoked the program. A program with the setgroup-id mode bit set may execute with a different group ID; that is called the effective group ID and is obtained by invoking the getegid system call. getpid #include <sys/types.h> pid_t getpid (void) getpid returns the process ID of the calling process; there is no error return. getpgrp pid_t getpgrp (void) getpgrp returns the process group ID of the calling process; there is no error return. A process group is used for the distribution of signals, and by terminals to arbitrate requests for their input.

6 getuid pid_t getuid (void) ioctl kill link getuid returns the real user ID of the calling process; there is no error return. The real user ID is that of the user who invoked the program. A program with the setuser-id mode bit set may execute with a different user ID; that is called the effective user ID and is obtained by invoking the geteuid system call. #include <sys/ioctl.h> int ioctl (int fd, unsigned long request,...) ioctl is used to manipulate the device parameters of special files (like terminals). The particular device to be affected is identified by the open file descriptor fd. The particular request to be performed is specified by request. Any additional information needed by the request will be specified in parameters following request. See the detailed documentation for more information on ioctl. #include <signal.h> int kill (pid_t pid, int sig) kill sends the signal sig to the process or group of processes identified by pid. Normally sig will be one of the signals that could be specified in the sigaction system call, but it can also be 0 which sends no signal, but can be used to verify the validity of pid. If pid is greater than 0, then it identifies a single process. If pid is 0, the signal is sent to all processes whose group ID is the same as the sending process. On success, kill returns 0. kill returns 1 and sets the global variable errno if an error is encountered. See the detailed documentation for more information on kill. int link (const char *path1, const char *path2) link atomically creates a new directory entry as specified by path2 with the attributes of the object pointed to by path1. That is, after successful execution of link, path1 and path2 refer to the same object, which has its link (reference) count incremented. Both path1 and path2 must be in the same file system, and path1 must previously exist. On success, link returns 0. link returns 1 and sets the global variable errno if an error is encountered.

7 lseek mkdir long lseek (int fd, long offset, int whence) lseek modifies the file position associated with the open file specified by fd. The file position is set to that specified by the whence parameter plus the value specified by the offset parameter. The possible values on whence are: SEEK_CUR SEEK_SET SEEK_END the offset is from the current file position the offset is from the beginning of the file the offset is from the end of the file If the file position is set beyond the end of file, and the file is written, an unwritten gap is created. When bytes in this unwritten gap are read, their values are effectively zero. Upon successful completion, lseek returns a long integer indicating the new setting of the file pointer. On devices incapable of seeking (i.e. a terminal), this position is undefined. Lseek returns 1 and sets the global variable errno if an error is encountered. #include <sys/stat.h> int mkdir (const char *path, mode_t mode) mkdir creates a new directory as specified by path with the access permissions specified by mode and restricted by the umask of the calling process. On success, mkdir returns 0. mkdir returns 1 and sets the global variable errno if an error is encountered. mknod #include <sys/stat.h> int mkdir (const char *path, mode_t mode, dev_t dev) mknod creates a new special file as specified by path with the major and minor device numbers extracted from mode. The access permissions of the new special file are constrained by the umask of the calling process. The dev argument identifies a configuration-dependent specification of a character or block I/O device if mode specifies that path is to be a character or block special file. Otherwise dev is ignored. The use of mknod is restricted to the super-user. On success, mknod returns 0. mknod returns 1 and sets the global variable errno if an error is encountered. mount #include <sys/param.h> #include <sys/mount.h> int mount (const char *type, const char *dir, int flags, void *data) mount grafts a filesystem object onto the system file tree at the point specified by dir. The type argument indicates how to interpret the data argument, which describes the

8 open filesystem object to be mounted. The flags argument is used to modify default semantics which affect filesystem access. After the filesystem object is successfully mounted on dir, any files in dir are hidden and are unavailable until the filesystem object is unmounted. On success, mount returns 0. mount returns 1 and sets the global variable errno if an error is encountered. See the detailed documentation for more information on mount. #include <fcntl.h> int open (char *path, int flags [, mode]) Open prepares the file specified by path for reading and/or writing as specified by flags and possibly mode. The flags may be specified using a bitwise or of one or more of the following: O_RDONLY O_WRONLY O_RDWR O_CREAT open for reading only open for writing only open for reading and writing create file if it does not exist O_TRUNC truncate size to 0 (and others not discussed here). If the O_CREAT flag is given and the file does not exist, the new file is given the specified mode (as described for the chmod system call), as modified by the process current umask. Upon successful completion, open returns a small integer called a file descriptor. This value is then used in other input/output system calls to reference the open file. Open also causes the file pointer (which marks the byte offset in the file where the next read or write system call will begin) to be set to zero. Open returns 1 and sets the global variable errno if an error is encountered. Common errors include attempting to open a file that doesn t exist, attempting to open a file without authority, attempting to open a directory for writing, and attempting to open a read-only file for writing. Each system also has a limit on the number of files that may be simultaneously open; exceeding this limit will also result in an error return from open. pause int pause (void) pause causes the calling process (or thread) to block (sleep) until a signal is delivered that either terminates the process or causes the invocation of a signal-handling function. The pause system call returns only when a signal is caught and the signal-handling function returns. In this case, pause returns -1, and errno is set to EINTR.

9 pipe int pipe (int *fd2) Pipe creates a pair of file descriptors which it stores in fd2[0] and fd2[1]. These file descriptors are effectively associated with the ends of an in-memory queue, so that data written into the pipe can later be read from it. fd2[0] is traditionally associated with the end of the pipe which can be read, and fd2[1] with the end of the pipe which can be written. The pipe persists until the file descriptors associated with each end are closed. End of file on a pipe is indicated when read returns 0. This can only occur when all file descriptors associated with the write end of the pipe have been closed. (Older UNIX systems used exclusively in-memory data structures for pipes, and thus a write operation could block if the maximum size of the queue was exceeded. Newer systems use different data structures that preclude this behavior.) Pipe returns 1 and sets the global variable errno if an error is encountered. It returns 0 on successful creation of the pipe. ptrace #include <sys/ptrace.h> long ptrace (enum_ptrace_request request, pid_t pid, void *addr, void *data) ptrace provides a facility to allow one process (the tracer ) to observe and control the execution of another process (the tracee ). The tracer may examine and change the tracee s memory and registers. Debuggers are the primary users of this system call. Details of the ptrace system call are found in the appropriate manual pages. pthread_cond_broadcast int pthread_cond_broadcast (pthread_cond_t *cond) All threads waiting for the condition variable cond are unblocked. If pthread_cond_broadcast is successful, it returns 0. Otherwise it returns a nonzero error code to indicate the error. pthread_cond_destroy int pthread_cond_destroy (pthread_cond_t *cond) All threads waiting for the condition variable cond are unblocked. If pthread_cond_broadcast is successful, it returns 0. Otherwise it returns a nonzero error code to indicate the error. pthread_cond_init int pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr) A new condition variable is created with attributes as specified by the attr argument. NULL can be used for the attr value to obtain default attributes. If successful, the new condition variable ID will be stored at cond.

10 If pthread_cond_init is successful, it returns 0. Otherwise it returns a non-zero error code to indicate the error. pthread_cond_signal int pthread_cond_signal (pthread_cond_t *cond) One thread waiting for the condition variable cond is unblocked. If pthread_cond_signal is successful, it returns 0. Otherwise it returns a non-zero error code to indicate the error. pthread_cond_wait int pthread_cond_init (pthread_cond_t *cond, pthread_mutex_t *mutex) The calling thread will be atomically blocked to wait for the specified condition variable cond to be signaled or broadcasted, and releases the lock on mutex (which should be locked before calling this function). When the waiting thread is unblocked, it will reacquire the lock on mutex. If pthread_cond_wait is successful, it returns 0. Otherwise it returns a non-zero error code to indicate the error. pthread_create int pthread_create (pthread_t *thread, const pthread_attr_t attr, void *(*start_routine)(void *), void *arg) pthread_create creates a new thread. thread is set to the ID of the created thread upon successful completion of the creation. attr identifies the attributes for the new thread; using NULL for attr yields the default attributes for the new thread, which are often appropriate. start_routine is the address of the function with which the thread will begin execution; normally this is just the name of a function. Note that this function must have a void * argument and return a void * result. Finally, arg is a pointer to an arbitrary (void) data item; it is passed to the thread s start routine. If the function identified by start_routine returns, the effect is as if there was an implicit call to pthread_exit using the return value of start_routine as the exit status. If pthread_create is successful, it returns 0. Otherwise it returns a non-zero error code to indicate the error. See the detailed documentation for more information on pthread_create.

11 pthread_exit void pthread_exit (void *value_ptr) The calling thread is terminated, and returns value_ptr to a thread that has blocked waiting for this thread to terminate. pthread_join int pthread_join (pthread_t *thread, void **value_ptr) After a successful call to pthread_join, the calling thread s execution is suspended (blocked) until the thread specified by thread terminates. If value_ptr is not NULL, then the value returned by pthread_exit is stored there. If pthread_join is successful, it returns 0. Otherwise it returns a non-zero error code to indicate the error. pthread_mutex_destroy int pthread_mutex_destroy (pthread_mutex_t *mutex) This function destroys (reclaims) the mutex identified by mutex. It is inappropriate to destroy a locked mutex If pthread_mutex_destroy is successful, it returns 0. Otherwise it returns a nonzero error code to indicate the error. pthread_mutex_init int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) A new mutex is created with attributes as specified by the attr argument. NULL can be used for the attr value to obtain default attributes. If successful, the new mutex ID will be stored at mutex. If pthread_mutex_init is successful, it returns 0. Otherwise it returns a non-zero error code to indicate the error. pthread_mutex_lock int pthread_mutex_lock (pthread_mutex_t *mutex) This function locks the unlocked mutex identified by mutex. If the mutex is already locked, the calling thread blocks until the mutex becomes available. If a recursive mutex is specified, the current owner can lock it again without being blocked. The lock count is incremented in this case. If pthread_mutex_lock is successful, it returns 0. Otherwise it returns a non-zero error code to indicate the error.

12 pthread_mutex_trylock int pthread_mutex_trylock (pthread_mutex_t *mutex) This function attempts to lock the mutex identified by mutex. If that mutex is already locked, the calling thread does not block, but will instead receive the error code EBUSY. If pthread_mutex_trylock is successful in its attempt to lock mutex, it returns 0. Otherwise it returns a non-zero error code to indicate the error. pthread_mutex_unlock int pthread_mutex_unlock (pthread_mutex_t *mutex) read This function attempts to unlock the mutex identified by mutex. If pthread_mutex_unlock is successful, it returns 0. Otherwise it returns a nonzero error code to indicate the error. #include <sys/types.h> #include <sys/uio.h> int read (int fd, void *buf, int nbytes) Read attempts to read nbytes bytes of data from the file referenced by the file descriptor fd into the buffer pointed to by buf. On devices capable of seeking (i.e. a disk file, but not a terminal), read begins transferring data from the location associated with the pointer associated with fd; upon completion of read, the pointer is incremented by the number of bytes actually read. On devices not capable of seeking, read always begins at the current file position. Upon successful completion, read returns the number of bytes actually read and placed in the buffer. If a disk file with sufficient data remaining is read, then the number of bytes read will be the number of bytes requested. If insufficient data is available, then the count of bytes read will be smaller than the number of bytes requested. In particular, reading from a terminal in normal (that is, cooked) mode will return no more than the number of bytes remaining in the current input line. When reading a disk file, a returned value less than nbytes indicates the end of file has been reached. When reading a terminal in normal mode, the end of file is indicated by a returned value of 0. Read returns 1 and sets the global variable errno if an error is encountered. In particular, a bad value for fd will result in an error. rename int rename (char *old, char *new) Rename changes the name of the file with the path old to the path new. Old and new must be of the same type (i.e. regular files or directories) and must reside on the same file system. rename returns 1 and sets the global variable errno if an error is encountered. It returns 0 on success.

13 rmdir sbrk int rmdir (const char *path) rmdir removes a directory whose name is given by path. The directory must not have any entries other than '.' and '..'. rmdir returns 0 on success. rmdir returns 1 and sets the global variable errno if an error is encountered void *sbrk (intptr_t increment) sbrk adds increment to the address associated with the program break, which is the first address beyond the end of the data region of the process. Calling sbrk with an increment of 0 can be used to find the address currently associated with the program break, as sbrk returns the prior address associated with the program break. The value of increment can be negative to return storage to the system. Applications rarely use sbrk directly, and instead depend on library mechanisms (like malloc in C and new in C++) to manage dynamically allocated memory. sbrk returns (void *) 1 and sets the global variable errno if an error is encountered. setgid int setgid (gid_t gid) setgid sets the real and effective group IDs of the current process to gid. It succeeds and returns 0 if the current effective ID is that of the super-user, or if the specified group ID gid is the same as the real group ID. setgid returns 1 and sets the global variable errno if an error is encountered. setsid pid_t setsid (void) setsid creates a new session if the calling process is not a process group leader. The calling process becomes the leader of the new session and the process group leader of the new process group; it has no controlling terminal. The process group ID and session ID of the calling process are set to the PID of the calling process. The calling process will be the only process in the new process group and the new session. On success, the new session ID of the calling process is returned. setsid returns (pid_t) 1 and sets the global variable errno if an error is encountered. setuid int setuid (uid_t uid) setuid sets the real and effective user IDs of the current process to uid. It succeeds and returns 0 if the current effective user ID is that of the super-user, or if the specified user ID uid is the same as the real user ID.

14 setuid returns 1 and sets the global variable errno if an error is encountered. sigaction #include <signal.h> int sigaction (int signum, struct sigaction *act, struct sigaction *oldact) sigaction is used to change the action taken by a process on receipt of a specific signal. The signum argument identifies the signal for which the action is to be taken; it can be any valid signal except sigkill and sigstop. If act is not NULL, then it specifies an action (SIG_DFL, SIG_IGN, or the signal handling function s address) and a signal mask to be used when delivering the specified signal. If oldact is not NULL, information about how the signal was previously handled is stored in the structure. See the detailed documentation for more information on sigaction. sigpending #include <signal.h> int sigpending (sigset_t *set) sigpending stores a mask of the signals pending delivery for the calling process at set. Signals may be pending delivery because they are currently masked. If the call succeeds, 0 is returned. sigpending returns 1 and sets the global variable errno if an error is encountered. sigprocmask #include <signal.h> int sigprocmask (int how, const sigset_t *set, sigset_t *old) sigprocmask examines and/or changes the current signal mask for the process. The signal mask specifies those signals that are blocked from delivery to the process. If the set argument is not NULL, the how parameter determines what the system call does. If how is SIG_BLOCK, then the new signal mask is the union of the current signal mask and set. If how is SIG_UNBLOCK, then the new signal mask is the intersection of the current signal mask and the complement of set. If how is SIG_SETMASK, then the new signal mask is replaced by set. The old signal mask for the process is saved at old if it is not NULL, regardless of the value of how. The signals SIGKILL and SIGSTOP cannot be blocked. sigprocmask returns 0 on success. sigprocmask returns 1 and sets the global variable errno if an error is encountered.

15 sigreturn int sigreturn (...) sigreturn is not intended to be called directly from a user process. Instead, it is called at the end of execution of a user s signal handling function. Its purpose is to restore the context that existed at the time the signal was delivered to the process. It is implementation dependent. sigsuspend #include <signal.h> int sigsuspend (const sigset_t *mask) stat stime sync sigsuspend temporarily replaces the signal mask for the process with mask, and then suspends (blocks) the calling process until one of the unmasked signals is delivered to the process and the appropriate signal handler is invoked, or a signal delivery terminates the process. If a signal delivery terminates the process, then sigsuspend does not return. If a signal handler is invoked, then when it returns, the signal mask for the process is restored to the value it had before sigsuspend was invoked. The signals SIGKILL and SIGSTOP cannot be blocked; their inclusion in mask will be ignored. sigsuspend returns 0 on success. sigsuspend returns 1 and sets the global variable errno if an error is encountered. #include <sys/types.h> #include <sys/stat.h> int stat (char *path, struct stat *sb) stat obtains information about the file pointed to by path. See the description of fstat for details. #include <time.h> int stime (const time_t *t) stime can only be successfully called by the super-user. In that case, the system s idea of the date and time is set from the value of t, which is the number of seconds since midnight UTC on January 1, 1970 (which is known in the UNIX world as the Epoch). stime returns 0 on success. stime returns 1 and sets the global variable errno if an error is encountered. void sync (void) sync causes all buffered modifications to file metadata and data to be queued for writing to the underlying file systems. It is always successful. Note that the write operations will likely not have completed when the system call returns. Some current systems (e.g. Linux) do wait until the write operations have been completed before returning. This still

16 time times does not guarantee the modified metadata and data have been successfully written to disk, because of the caching operations common in modern disk drives. #include <time.h> time_t time (time_t *tloc) time returns the system s idea of the date and time as the number of seconds past the Epoch (see stime). If tloc is not NULL, the value is also stored there. time returns 1 and sets the global variable errno if an error is encountered. #include <sys/times.h> clock_t times (struct tms *buf) times stores the process use times in the members of the structure pointed to by buf. There are at least four members, each with type clock_t: tms_utime is the time spent in user mode executing instructions of the calling process. tms_stime is the time spent in kernel mode executing actions on behalf of the calling process (typically system calls). tms_cutime and tms_cstime are the same as tms_utime and tms_stime, except they specify times for the child processes on which the current process has successfully waited, including the descendants of those child processes. times returns the number of clock ticks that have elapsed since an arbitrary point in the past. It returns 1 and sets the global variable errno if an error is encountered. The number of clock ticks per second can be determined by calling sysconf(_sc_clk_tck). This function returns a long and the unistd.h header file should be included if it is used. umask #include <sys/types.h> #include <sys/stat.h> mode_t umask (mode_t mask) umask sets the file mode creation mask (called umask) for the process to mask & 0777 (that is, only the low-order 9 bits of mask are used). The previous value of the umask is returned; there is no error return possible. Various system calls (including open and mkdir) use umask to modify the permissions set on newly created files or directories. In particular, permissions in the umask are turned off (set to 0) in the mode used by these system calls. umount #include <sys/mount.h> int umount (const char *target) umount unmounts the uppermost (last) file system mounted on the directory specified by target. It returns 0 if successful. umount returns 1 and sets the global variable errno if an error is encountered.

17 unlink int unlink (const char *path) utime wait unlink removes a link to the file named by path and reduces the link (reference) count for the file object. If the link count is reduced to 0, then if no processes have the file open, all resources associated with the file are reclaimed. If one or more processes have the file open at the time unlink is executed and the link count is reduced to 0, the resource reclamation is deferred until such time as the processes have each closed the file. unlink returns 0 on success. unlink returns 1 and sets the global variable errno if an error is encountered. #include <sys/types.h> #include <utime.h> int utime (const char *path, const struct utimbuf *times) utime changes the access and modification times of the inode associated with the object identified by path to those in the actime and modtime members of the structure at times. See the full documentation for additional details. utime returns 0 on success. utime returns 1 and sets the global variable errno if an error is encountered. #include <sys/types.h> #include <sys/wait.h> int wait (int *status) wait suspends (blocks) execution of the calling process until any of its child processes terminates. status, if not null, point to a location where information about the terminated process is stored, specifically why the process terminated (normal termination or some other failure) and the least significant 8 bits of the argument to the exit system call or the value returned by a main function. See the full documentation for details on the arguments. On success, wait returns the process ID of the terminated child process. On error (e.g. there were no child processes), wait returns 1. waitpid #include <sys/types.h> #include <sys/wait.h> int waitpid (pid_t pid, int *status, int options) waitpid suspends (blocks) execution of the calling process until the child process specified by pid terminates. pid, when positive, identifies a specific process, but other values may be used. options is often 0. status, if not null, point to a location where information about the terminated process is stored, specifically why the process terminated (normal termination or some other failure) and the least significant 8 bits of the argument to the exit system call or the value returned by a errno function. See the full documentation for details on the arguments.

18 write int write (int fd, void *buf, int nbytes) Write attempts to write nbytes bytes of data to the file referenced by the file descriptor fd from the buffer pointed to by buf. On devices capable of seeking (e.g. a disk file, but not a terminal), write begins transferring data to the location associated with the pointer associated with fd; upon completion of write, the pointer is incremented by the number of bytes actually written. On devices not capable of seeking, write always begins at the current file position. Upon successful completion, write returns the number of bytes actually written. Write returns 1 and sets the global variable errno if an error is encountered. In particular, a bad value for fd will result in an error.

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell

More information

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell

More information

UNIX System Calls. Sys Calls versus Library Func

UNIX System Calls. Sys Calls versus Library Func UNIX System Calls Entry points to the kernel Provide services to the processes One feature that cannot be changed Definitions are in C For most system calls a function with the same name exists in the

More information

System Calls. Library Functions Vs. System Calls. Library Functions Vs. System Calls

System Calls. Library Functions Vs. System Calls. Library Functions Vs. System Calls System Calls Library Functions Vs. System Calls A library function: Ordinary function that resides in a library external to the calling program. A call to a library function is just like any other function

More information

Building blocks for Unix power tools

Building blocks for Unix power tools for Unix power tools Now that we have given a good overview of a lot of the better Unix tools, I want to take some time to talk about our toolset for building Unix programs. The most important of these

More information

Overview. Over the next four weeks, we will look at these topics: Building Blocks. Advanced Authentication Issues.

Overview. Over the next four weeks, we will look at these topics: Building Blocks. Advanced Authentication Issues. Overview Over the next four weeks, we will look at these topics: Building Blocks Advanced Authentication Issues Security Overview Storage and its abstraction Virtualization and appliances Data Replication

More information

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University File I/O Hyo-bong Son (proshb@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unix Files A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O

More information

Lecture files in /home/hwang/cs375/lecture05 on csserver.

Lecture files in /home/hwang/cs375/lecture05 on csserver. Lecture 5 Lecture files in /home/hwang/cs375/lecture05 on csserver. cp -r /home/hwang/cs375/lecture05. scp -r user@csserver.evansville.edu:/home/hwang/cs375/lecture05. Project 1 posted, due next Thursday

More information

THREADS. Jo, Heeseung

THREADS. Jo, Heeseung THREADS Jo, Heeseung TODAY'S TOPICS Why threads? Threading issues 2 PROCESSES Heavy-weight A process includes many things: - An address space (all the code and data pages) - OS resources (e.g., open files)

More information

LSN 13 Linux Concurrency Mechanisms

LSN 13 Linux Concurrency Mechanisms LSN 13 Linux Concurrency Mechanisms ECT362 Operating Systems Department of Engineering Technology LSN 13 Creating Processes fork() system call Returns PID of the child process created The new process is

More information

4. System Functions and Subroutines

4. System Functions and Subroutines Chapter 4 4. System s and Subroutines This chapter describes extensions to Fortran 77 that are related to the IRIX compiler and operating system. Library s summarizes the Fortran run-time library functions.

More information

Files and Directories

Files and Directories Files and Directories Stat functions Given pathname, stat function returns structure of information about file fstat function obtains information about the file that is already open lstat same as stat

More information

CptS 360 (System Programming) Unit 6: Files and Directories

CptS 360 (System Programming) Unit 6: Files and Directories CptS 360 (System Programming) Bob Lewis School of Engineering and Applied Sciences Washington State University Spring, 2019 Motivation Need to know your way around a filesystem. A properly organized filesystem

More information

Files and Directories Filesystems from a user s perspective

Files and Directories Filesystems from a user s perspective Files and Directories Filesystems from a user s perspective Unix Filesystems Seminar Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of

More information

Lesson 3. The func procedure allows a user to choose the action upon receipt of a signal.

Lesson 3. The func procedure allows a user to choose the action upon receipt of a signal. Lesson 3 Signals: When a process terminates abnormally, it usually tries to send a signal indicating what went wrong. C programs can trap these for diagnostics. Software interrupts: Stop executing the

More information

Chp1 Introduction. Introduction. Objective. Logging In. Shell. Briefly describe services provided by various versions of the UNIX operating system.

Chp1 Introduction. Introduction. Objective. Logging In. Shell. Briefly describe services provided by various versions of the UNIX operating system. Chp1 Objective Briefly describe services provided by various versions of the UNIX operating system. Logging In /etc/passwd local machine or NIS DB root:x:0:1:super-user:/root:/bin/tcsh Login-name, encrypted

More information

OPERATING SYSTEMS: Lesson 2: Operating System Services

OPERATING SYSTEMS: Lesson 2: Operating System Services OPERATING SYSTEMS: Lesson 2: Operating System Services Jesús Carretero Pérez David Expósito Singh José Daniel García Sánchez Francisco Javier García Blas Florin Isaila 1 Goals To understand what an operating

More information

CSC 271 Software I: Utilities and Internals

CSC 271 Software I: Utilities and Internals CSC 271 Software I: Utilities and Internals Lecture 13 : An Introduction to File I/O in Linux File Descriptors All system calls for I/O operations refer to open files using a file descriptor (a nonnegative

More information

Unix System Programming - Chapter 8

Unix System Programming - Chapter 8 Unix System Programming - Chapter 8 Neal Nelson The Evergreen State College Apr 2010 USP Chapter 8 - Signals Section 8.1 - Basic Signal Concepts Section 8.2 - Generating Signals Section 8.3 - Signal Masks

More information

Lecture 23: System-Level I/O

Lecture 23: System-Level I/O CSCI-UA.0201-001/2 Computer Systems Organization Lecture 23: System-Level I/O Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted (and slightly modified) from: Clark Barrett

More information

CS 201. Files and I/O. Gerson Robboy Portland State University

CS 201. Files and I/O. Gerson Robboy Portland State University CS 201 Files and I/O Gerson Robboy Portland State University A Typical Hardware System CPU chip register file ALU system bus memory bus bus interface I/O bridge main memory USB controller graphics adapter

More information

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D) MANAGEMENT OF APPLICATION EXECUTION PROCESS CONTROL BLOCK Resources (processor, I/O devices, etc.) are made available to multiple applications The processor in particular is switched among multiple applications

More information

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 3 Oral test Handin your slides Time Project 4 Due: 6 Dec Code Experiment report Operating System Labs Overview of file system File

More information

CS , Spring Sample Exam 3

CS , Spring Sample Exam 3 Andrew login ID: Full Name: CS 15-123, Spring 2010 Sample Exam 3 Mon. April 6, 2009 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the

More information

CMPS 105 Systems Programming. Prof. Darrell Long E2.371

CMPS 105 Systems Programming. Prof. Darrell Long E2.371 + CMPS 105 Systems Programming Prof. Darrell Long E2.371 darrell@ucsc.edu + Chapter 3: File I/O 2 + File I/O 3 n What attributes do files need? n Data storage n Byte stream n Named n Non-volatile n Shared

More information

CS 326: Operating Systems. Process Execution. Lecture 5

CS 326: Operating Systems. Process Execution. Lecture 5 CS 326: Operating Systems Process Execution Lecture 5 Today s Schedule Process Creation Threads Limited Direct Execution Basic Scheduling 2/5/18 CS 326: Operating Systems 2 Today s Schedule Process Creation

More information

CSI 402 Lecture 11 (Unix Discussion on Files continued) 11 1 / 19

CSI 402 Lecture 11 (Unix Discussion on Files continued) 11 1 / 19 CSI 402 Lecture 11 (Unix Discussion on Files continued) 11 1 / 19 User and Group IDs Ref: Chapter 3 of [HGS]. Each user is given an ID (integer) called uid. (Most system programs use uid instead of the

More information

CSci 4061 Introduction to Operating Systems. File Systems: Basics

CSci 4061 Introduction to Operating Systems. File Systems: Basics CSci 4061 Introduction to Operating Systems File Systems: Basics File as Abstraction Naming a File creat/open ( path/name, ); Links: files with multiple names Each name is an alias #include

More information

Computer Systems Laboratory Sungkyunkwan University

Computer Systems Laboratory Sungkyunkwan University Threads Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Why threads? Threading issues 2 Processes Heavy-weight A process includes

More information

Threads. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Threads. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Threads Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3052: Introduction to Operating Systems, Fall 2017, Jinkyu Jeong (jinkyu@skku.edu) Concurrency

More information

COSC 6374 Parallel Computation. Shared memory programming with POSIX Threads. Edgar Gabriel. Fall References

COSC 6374 Parallel Computation. Shared memory programming with POSIX Threads. Edgar Gabriel. Fall References COSC 6374 Parallel Computation Shared memory programming with POSIX Threads Fall 2012 References Some of the slides in this lecture is based on the following references: http://www.cobweb.ecn.purdue.edu/~eigenman/ece563/h

More information

Processes. Processes (cont d)

Processes. Processes (cont d) Processes UNIX process creation image-file arg1 arg2 Shell command line example ls -l Equivalent to /bin/ls -l Why? How do you find out where the image file is? Background processes ls -l & Execute a process

More information

Shell Execution of Programs. Process Groups, Session and Signals 1

Shell Execution of Programs. Process Groups, Session and Signals 1 Shell Execution of Programs Process Groups, Session and Signals 1 Signal Concepts Signals are a way for a process to be notified of asynchronous events (software interrupts). Some examples: a timer you

More information

Parents and Children

Parents and Children 1 Process Identifiers Every process apart from the PID also has a PUID and a PGID. There are two types of PUID and PGID: real and effective. The real PUID is always equal to the user running the process

More information

Introduction to PThreads and Basic Synchronization

Introduction to PThreads and Basic Synchronization Introduction to PThreads and Basic Synchronization Michael Jantz, Dr. Prasad Kulkarni Dr. Douglas Niehaus EECS 678 Pthreads Introduction Lab 1 Introduction In this lab, we will learn about some basic synchronization

More information

CS2028 -UNIX INTERNALS

CS2028 -UNIX INTERNALS DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY,SIRUVACHUR-621113. CS2028 -UNIX INTERNALS PART B UNIT 1 1. Explain briefly details about History of UNIX operating system? In 1965, Bell Telephone

More information

which maintain a name to inode mapping which is convenient for people to use. All le objects are

which maintain a name to inode mapping which is convenient for people to use. All le objects are UNIX Directory Organization UNIX directories are simple (generally ASCII) les which maain a name to inode mapping which is convenient for people to use. All le objects are represented by one or more names

More information

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto For more information please consult Advanced Programming in the UNIX Environment, 3rd Edition, W. Richard Stevens and

More information

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line Operating Systems Lecture 06 System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line March 04, 2013 exec() Typically the exec system call is

More information

File I/0. Advanced Programming in the UNIX Environment

File I/0. Advanced Programming in the UNIX Environment File I/0 Advanced Programming in the UNIX Environment File Descriptors Created and managed by the UNIX kernel. Created using open or creat system call. Used to refer to an open file UNIX System shells

More information

UNIT I INTRODUCTION TO UNIX & FILE SYSTEM

UNIT I INTRODUCTION TO UNIX & FILE SYSTEM INTRODUCTION TO UNIX & FILE SYSTEM Part A 1. What is UNIX? UNIX(Uniplexed Information Computing System) it is an operating system was developed in Early 1970 at Bell Labs. It was initially a character

More information

Logical disks. Bach 2.2.1

Logical disks. Bach 2.2.1 Logical disks Bach 2.2.1 Physical disk is divided into partitions or logical disks Logical disk linear sequence of fixed size, randomly accessible, blocks disk device driver maps underlying physical storage

More information

Lecture 21 Systems Programming in C

Lecture 21 Systems Programming in C Lecture 21 Systems Programming in C A C program can invoke UNIX system calls directly. A system call can be defined as a request to the operating system to do something on behalf of the program. During

More information

Design Overview of the FreeBSD Kernel CIS 657

Design Overview of the FreeBSD Kernel CIS 657 Design Overview of the FreeBSD Kernel CIS 657 Organization of the Kernel Machine-independent 86% of the kernel (80% in 4.4BSD) C code Machine-dependent 14% of kernel Only 0.6% of kernel in assembler (2%

More information

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent? Design Overview of the FreeBSD Kernel CIS 657 Organization of the Kernel Machine-independent 86% of the kernel (80% in 4.4BSD) C C code Machine-dependent 14% of kernel Only 0.6% of kernel in assembler

More information

Linux is obsolete 2.0

Linux is obsolete 2.0 CCCamp 2007 Tanenbaum versus Brown Thus, of course, Linus didn t sit down in a vacuum and suddenly type in the Linux source code. He had my book, was running MINIX, and undoubtedly knew the history (since

More information

System- Level I/O. Andrew Case. Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron

System- Level I/O. Andrew Case. Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron System- Level I/O Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron 1 Unix I/O and Files UNIX abstracts many things into files (just a series of bytes) All I/O devices are represented

More information

File I/O. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

File I/O. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University  Embedded Software Lab. 1 File I/O Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University http://nyx.skku.ac.kr Unix files 2 A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O devices are represented

More information

RTEMS POSIX API User s Guide

RTEMS POSIX API User s Guide RTEMS POSIX API User s Guide Edition 1, for RTEMS 4.5.0-beta3 May 2000 On-Line Applications Research Corporation On-Line Applications Research Corporation TEXinfo 1999-09-25.10 COPYRIGHT c 1988-2000. On-Line

More information

Overview. Administrative. * HW 1 grades. * HW 2 Due. Topics. * 5.1 What is a Signal? * Dealing with Signals - masks, handlers

Overview. Administrative. * HW 1 grades. * HW 2 Due. Topics. * 5.1 What is a Signal? * Dealing with Signals - masks, handlers Overview Administrative * HW 1 grades * HW 2 Due Topics * 5.1 What is a Signal? * 5.2-3 Dealing with Signals - masks, handlers * 5.4 Synchronization: pause(), sigsuspend() * 5.6 Interaction with other

More information

File and Directories. Advanced Programming in the UNIX Environment

File and Directories. Advanced Programming in the UNIX Environment File and Directories Advanced Programming in the UNIX Environment stat Function #include int stat(const char *restrict pathname, struct stat *restrict buf ); int fstat(int fd, struct stat

More information

Advanced Programming in the UNIX Environment W. Richard Stevens

Advanced Programming in the UNIX Environment W. Richard Stevens Advanced Programming in the UNIX Environment W. Richard Stevens ADDISON-WESLEY PUBLISHING COMPANY Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario Wokingham, England Amsterdam

More information

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 4 (multi-thread & lock): Due: 10 Dec Code & experiment report 18 Dec. Oral test of project 4, 9:30am Lectures: Q&A Project 5: Due:

More information

Process Creation in UNIX

Process Creation in UNIX Process Creation in UNIX int fork() create a child process identical to parent Child process has a copy of the address space of the parent process On success: Both parent and child continue execution at

More information

Department of Computer Science and Technology, UTU 2014

Department of Computer Science and Technology, UTU 2014 Short Questions 060010601 Unix Internals Unit 1 : Introduction and Overview of UNIX 1. What were the goals of Multics System? 2. List out the levels in which UNIX system architecture is divided. 3. Which

More information

File Descriptors and Piping

File Descriptors and Piping File Descriptors and Piping CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 8 Today s topics File Descriptors

More information

Threads need to synchronize their activities to effectively interact. This includes:

Threads need to synchronize their activities to effectively interact. This includes: KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 8 Threads Synchronization ( Mutex & Condition Variables ) Objective: When multiple

More information

Contents. NOTICE & Programming Assignment #1. QnA about last exercise. File IO exercise

Contents. NOTICE & Programming Assignment #1. QnA about last exercise. File IO exercise File I/O Examples Prof. Jin-Soo Kim(jinsookim@skku.edu) TA - Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents NOTICE & Programming Assignment

More information

Process Management! Goals of this Lecture!

Process Management! Goals of this Lecture! Process Management! 1 Goals of this Lecture! Help you learn about:" Creating new processes" Programmatically redirecting stdin, stdout, and stderr" Unix system-level functions for I/O" The Unix stream

More information

CSCI4430 Data Communication and Computer Networks. Pthread Programming. ZHANG, Mi Jan. 26, 2017

CSCI4430 Data Communication and Computer Networks. Pthread Programming. ZHANG, Mi Jan. 26, 2017 CSCI4430 Data Communication and Computer Networks Pthread Programming ZHANG, Mi Jan. 26, 2017 Outline Introduction What is Multi-thread Programming Why to use Multi-thread Programming Basic Pthread Programming

More information

POSIX PTHREADS PROGRAMMING

POSIX PTHREADS PROGRAMMING POSIX PTHREADS PROGRAMMING Download the exercise code at http://www-micrel.deis.unibo.it/~capotondi/pthreads.zip Alessandro Capotondi alessandro.capotondi(@)unibo.it Hardware Software Design of Embedded

More information

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm CSE333 SECTION 5 Important Dates October 27 th Homework 2 Due October 29 th Midterm String API vs. Byte API Recall: Strings are character arrays terminated by \0 The String API (functions that start with

More information

pthreads CS449 Fall 2017

pthreads CS449 Fall 2017 pthreads CS449 Fall 2017 POSIX Portable Operating System Interface Standard interface between OS and program UNIX-derived OSes mostly follow POSIX Linux, macos, Android, etc. Windows requires separate

More information

All the scoring jobs will be done by script

All the scoring jobs will be done by script File I/O Prof. Jin-Soo Kim( jinsookim@skku.edu) TA Sanghoon Han(sanghoon.han@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Announcement (1) All the scoring jobs

More information

Operating Systems. Lecture 05

Operating Systems. Lecture 05 Operating Systems Lecture 05 http://web.uettaxila.edu.pk/cms/sp2013/seosbs/ February 25, 2013 Process Scheduling, System Calls Execution (Fork,Wait,Exit,Exec), Inter- Process Communication Schedulers Long

More information

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls Lecture 3 Introduction to Unix Systems Programming: Unix File I/O System Calls 1 Unix File I/O 2 Unix System Calls System calls are low level functions the operating system makes available to applications

More information

The course that gives CMU its Zip! I/O Nov 15, 2001

The course that gives CMU its Zip! I/O Nov 15, 2001 15-213 The course that gives CMU its Zip! I/O Nov 15, 2001 Topics Files Unix I/O Standard I/O A typical hardware system CPU chip register file ALU system bus memory bus bus interface I/O bridge main memory

More information

ANSI/IEEE POSIX Standard Thread management

ANSI/IEEE POSIX Standard Thread management Pthread Prof. Jinkyu Jeong( jinkyu@skku.edu) TA Jinhong Kim( jinhong.kim@csl.skku.edu) TA Seokha Shin(seokha.shin@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The

More information

File Systems. q Files and directories q Sharing and protection q File & directory implementation

File Systems. q Files and directories q Sharing and protection q File & directory implementation File Systems q Files and directories q Sharing and protection q File & directory implementation Files and file systems Most computer applications need to Store large amounts of data; larger than their

More information

Shared Memory Memory mapped files

Shared Memory Memory mapped files Shared Memory Memory mapped files 1 Shared Memory Introduction Creating a Shared Memory Segment Shared Memory Control Shared Memory Operations Using a File as Shared Memory 2 Introduction Shared memory

More information

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu CPSC 341 OS & Networks Processes Dr. Yingwu Zhu Process Concept Process a program in execution What is not a process? -- program on a disk A process is an active object, but a program is just a file It

More information

11/3/71 SYS BREAK (II)

11/3/71 SYS BREAK (II) 11/3/71 SYS BREAK (II) break -- set program break SYNOPSIS sys break; addr / break = 17. break sets the system s idea of the highest location used by the program to addr. Locations greater than addr and

More information

Chapter 4 - Files and Directories. Information about files and directories Management of files and directories

Chapter 4 - Files and Directories. Information about files and directories Management of files and directories Chapter 4 - Files and Directories Information about files and directories Management of files and directories File Systems Unix File Systems UFS - original FS FFS - Berkeley ext/ext2/ext3/ext4 - Linux

More information

Process Management! Goals of this Lecture!

Process Management! Goals of this Lecture! Process Management! 1 Goals of this Lecture! Help you learn about:" Creating new processes" Programmatically redirecting stdin, stdout, and stderr" (Appendix) communication between processes via pipes"

More information

Process Management 1

Process Management 1 Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Programmatically redirecting stdin, stdout, and stderr (Appendix) communication between processes via pipes Why?

More information

CSci 4061 Introduction to Operating Systems. (Advanced Control Signals)

CSci 4061 Introduction to Operating Systems. (Advanced Control Signals) CSci 4061 Introduction to Operating Systems (Advanced Control Signals) What is a Signal? Signals are a form of asynchronous IPC Earlier: Non-blocking I/O and check if it has happened => polling Problem

More information

Noorul Islam College Of Engineering, Kumaracoil MCA Degree Model Examination (October 2007) 5 th Semester MC1642 UNIX Internals 2 mark Questions

Noorul Islam College Of Engineering, Kumaracoil MCA Degree Model Examination (October 2007) 5 th Semester MC1642 UNIX Internals 2 mark Questions Noorul Islam College Of Engineering, Kumaracoil MCA Degree Model Examination (October 2007) 5 th Semester MC1642 UNIX Internals 2 mark Questions 1. What are the different parts of UNIX system? i. Programs

More information

CS631 - Advanced Programming in the UNIX Environment

CS631 - Advanced Programming in the UNIX Environment CS631 - Advanced Programming in the UNIX Environment Slide 1 CS631 - Advanced Programming in the UNIX Environment Files and Directories Department of Computer Science Stevens Institute of Technology Jan

More information

File I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

File I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University File I/O Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unix Files A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O devices

More information

IMPLEMENTATION OF SIGNAL HANDLING. CS124 Operating Systems Fall , Lecture 15

IMPLEMENTATION OF SIGNAL HANDLING. CS124 Operating Systems Fall , Lecture 15 IMPLEMENTATION OF SIGNAL HANDLING CS124 Operating Systems Fall 2017-2018, Lecture 15 2 Signal Handling UNIX operating systems allow es to register for and handle signals Provides exceptional control flow

More information

Fall 2017 :: CSE 306. File Systems Basics. Nima Honarmand

Fall 2017 :: CSE 306. File Systems Basics. Nima Honarmand File Systems Basics Nima Honarmand File and inode File: user-level abstraction of storage (and other) devices Sequence of bytes inode: internal OS data structure representing a file inode stands for index

More information

PROCESS CONTROL: PROCESS CREATION: UNIT-VI PROCESS CONTROL III-II R

PROCESS CONTROL: PROCESS CREATION: UNIT-VI PROCESS CONTROL III-II R PROCESS CONTROL: This will describe the use and implementation of the system calls that control the process context. The fork system call creates a new process, the exit call terminates process execution,

More information

UNIT I Linux Utilities

UNIT I Linux Utilities UNIT I Linux Utilities 1. a) How does Linux differ from Unix? Discuss the features of Linux. 5M b) Explain various text processing utilities, with a suitable example for each. 5M 2. a) Explain briefly

More information

Contents. IPC (Inter-Process Communication) Representation of open files in kernel I/O redirection Anonymous Pipe Named Pipe (FIFO)

Contents. IPC (Inter-Process Communication) Representation of open files in kernel I/O redirection Anonymous Pipe Named Pipe (FIFO) Pipes and FIFOs Prof. Jin-Soo Kim( jinsookim@skku.edu) TA JinHong Kim( jinhong.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents IPC (Inter-Process Communication)

More information

File Systems. Today. Next. Files and directories File & directory implementation Sharing and protection. File system management & examples

File Systems. Today. Next. Files and directories File & directory implementation Sharing and protection. File system management & examples File Systems Today Files and directories File & directory implementation Sharing and protection Next File system management & examples Files and file systems Most computer applications need to: Store large

More information

Contents. Programming Assignment 0 review & NOTICE. File IO & File IO exercise. What will be next project?

Contents. Programming Assignment 0 review & NOTICE. File IO & File IO exercise. What will be next project? File I/O Prof. Jin-Soo Kim(jinsookim@skku.edu) TA - Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents Programming Assignment 0 review & NOTICE

More information

Pthreads. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Pthreads. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Pthreads Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Pthreads API ANSI/IEEE POSIX1003.1-1995 Standard Thread management Work directly on

More information

Synchronization. Semaphores implementation

Synchronization. Semaphores implementation Synchronization Semaphores implementation Possible implementations There are seeral possible implementations (standard and non standard)of a semaphore Semaphores through pipe POSIX semaphores Linux semaphores

More information

Systems Programming. COSC Software Tools. Systems Programming. High-Level vs. Low-Level. High-Level vs. Low-Level.

Systems Programming. COSC Software Tools. Systems Programming. High-Level vs. Low-Level. High-Level vs. Low-Level. Systems Programming COSC 2031 - Software Tools Systems Programming (K+R Ch. 7, G+A Ch. 12) The interfaces we use to work with the operating system In this case: Unix Programming at a lower-level Systems

More information

Outline. Relationship between file descriptors and open files

Outline. Relationship between file descriptors and open files Outline 3 File I/O 3-1 3.1 File I/O overview 3-3 3.2 open(), read(), write(), and close() 3-7 3.3 The file offset and lseek() 3-21 3.4 Atomicity 3-30 3.5 Relationship between file descriptors and open

More information

Signals. CSC209: Software Tools and Systems Programming. Furkan Alaca & Paul Vrbik

Signals. CSC209: Software Tools and Systems Programming. Furkan Alaca & Paul Vrbik Signals CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 9 Acknowledgement These slides are built upon material

More information

ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem

ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem ELEC-C7310 Sovellusohjelmointi Lecture 3: Filesystem Risto Järvinen September 21, 2015 Lecture contents Filesystem concept. System call API. Buffered I/O API. Filesystem conventions. Additional stuff.

More information

read(2) There can be several cases where read returns less than the number of bytes requested:

read(2) There can be several cases where read returns less than the number of bytes requested: read(2) There can be several cases where read returns less than the number of bytes requested: EOF reached before requested number of bytes have been read Reading from a terminal device, one line read

More information

17: Filesystem Examples: CD-ROM, MS-DOS, Unix

17: Filesystem Examples: CD-ROM, MS-DOS, Unix 17: Filesystem Examples: CD-ROM, MS-DOS, Unix Mark Handley CD Filesystems ISO 9660 Rock Ridge Extensions Joliet Extensions 1 ISO 9660: CD-ROM Filesystem CD is divided into logical blocks of 2352 bytes.

More information

All the scoring jobs will be done by script

All the scoring jobs will be done by script File I/O Prof. Jinkyu Jeong( jinkyu@skku.edu) TA-Seokha Shin(seokha.shin@csl.skku.edu) TA-Jinhong Kim( jinhong.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu

More information

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES Your name: SUNet ID: In accordance with both the letter and the spirit of the Stanford Honor Code, I did not cheat on this exam. Furthermore,

More information

EPL372 Lab Exercise 2: Threads and pthreads. Εργαστήριο 2. Πέτρος Παναγή

EPL372 Lab Exercise 2: Threads and pthreads. Εργαστήριο 2. Πέτρος Παναγή EPL372 Lab Exercise 2: Threads and pthreads Εργαστήριο 2 Πέτρος Παναγή 1 Threads Vs Processes 2 Process A process is created by the operating system, and requires a fair amount of "overhead". Processes

More information

Naked C Lecture 6. File Operations and System Calls

Naked C Lecture 6. File Operations and System Calls Naked C Lecture 6 File Operations and System Calls 20 August 2012 Libc and Linking Libc is the standard C library Provides most of the basic functionality that we've been using String functions, fork,

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to

More information

INTRODUCTION TO THE UNIX FILE SYSTEM 1)

INTRODUCTION TO THE UNIX FILE SYSTEM 1) INTRODUCTION TO THE UNIX FILE SYSTEM 1) 1 FILE SHARING Unix supports the sharing of open files between different processes. We'll examine the data structures used by the kernel for all I/0. Three data

More information