DOC PREVIEW
FSU COP 4342 - Building blocks for Unix power tools

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Fall 2006 Building blocksBuilding blocks for Unix power toolsNow that we have given a good overview of a lot ofthe better Unix tools, I want to take some time to talkabout our toolset for building Unix programs.The most important of these are the system calls.COP 4342Fall 2006 Building blocksBuilding blocks for Unix power toolsA Unix system call is a direct request to the kernelregarding a system resource. It might be a requestfor a file descriptor to manipulate a file, it might be arequest to write to a file descriptor, or any of hundredsof possible operations.These are exactly the tools that every Unix programis built upon.COP 4342Fall 2006 Building blocksFile descriptor and file descriptoroperationsIn some sense, the mainstay operations are thoseon the file system.COP 4342Fall 2006 Building blocksFile descriptor and file descriptoroperationsUnlike many other resources which are just artifactsof the operating system and disappear at each reboot,changing a file system generally is an operationthat has some permanence (although of course itis possible and even common to have “RAM” diskfilesystems since they are quite fast, and for itemsthat are meant to be temporary anyway, they are quiteacceptable.)COP 4342Fall 2006 Building blocksImportant file descriptor callsA file descriptor is an int. It provides stateful accessto an i/o resource such as a file on a filesystem, apseudo-terminal, or a socket to a tcp session.open() -- create a new file descriptor to access a fileclose() -- deallocate a file descriptorCOP 4342Fall 2006 Building blocksImportant file descriptor callsdup() -- duplicate a file descriptordup2() -- duplicate a file descriptorCOP 4342Fall 2006 Building blocksImportant file descriptor callsfchmod() -- change the permissions of a file associated with a file-- descriptorfchown() -- change the ownership of a file assocaited with a fileCOP 4342Fall 2006 Building blocksImportant file descriptor callsfcntl() -- miscellaneous manipulation of file descriptors: dup(), set-- close on exec(), set to non-blocking, set to asynchronous-- mode, locks, signalsioctl() -- manipulate the underlying ‘‘device’’ parameters forCOP 4342Fall 2006 Building blocksImportant file descriptor callsflock() -- lock a file associated with a file descriptorCOP 4342Fall 2006 Building blocksImportant file descriptor callspipe() -- create a one-way association between two file-- descriptors so that output from-- one goes to the input of the otherCOP 4342Fall 2006 Building blocksImportant file descriptor callsselect() -- multiplex on pending i/o to or from a set of file descriptorsCOP 4342Fall 2006 Building blocksImportant file descriptor callsread() -- send data to a file descriptorwrite() -- take data from a file descriptorCOP 4342Fall 2006 Building blocksImportant file descriptor callsreaddir() -- raw read of directory entry from a file descriptorCOP 4342Fall 2006 Building blocksImportant file descriptor callsfstat() -- return information about a file associated with a fd: inode,perms, hard links, uid, gid, size, modtimesfstatfs() -- return the mount information for the filesystem that the file-- descriptor is associated withCOP 4342Fall 2006 Building blocksImportant filesystem operationsIn addition to using the indirect means of filedescriptors, Unix also offers a number of directfunctions on files.access() -- returns a value indicating if a file is accessiblechmod() -- changes the permissions on a file in a filesystemchown() -- changes the ownership of a file in a filesystemCOP 4342Fall 2006 Building blocksImportant filesystem operationslink() -- create a hard link to a filesymlink() -- create a soft link to a fileCOP 4342Fall 2006 Building blocksImportant filesystem operationsmkdir() -- create a new directoryrmdir() -- remove a directoryCOP 4342Fall 2006 Building blocksImportant filesystem operationsstat() -- return information about a file associated with a fd: inode,perms, hard links, uid, gid, size, modtimesstatfs() -- return the mount information for the filesystem that the file-- descriptor is associated withCOP 4342Fall 2006 Building blocksSignalsalarm -- set an alarm clock for a SIGALRM to be sent to a process-- time measured in secondsgetitimer -- set an alarm clock in fractions of a second to deliver either-- SIGALRM, SIGVTALRM, SIGPROFCOP 4342Fall 2006 Building blocksSignalskill -- send an arbitrary signal to an arbitrary processkillpg -- send an arbitrary signal to all processes in a process groupCOP 4342Fall 2006 Building blocksSignalssigaction -- interpose a signal handler (can include special ‘‘default’’ or-- ‘‘ignore’’ handlers)sigprocmask -- change the list of blocked signalsCOP 4342Fall 2006 Building blocksSignalswait -- check for a signal (can be blocking or non-blocking) or child exitingwaitpid -- check for a signal from a child process (can be general or specific)COP 4342Fall 2006 Building blocksModifying the current process’s statechdir -- change the working directory for a process to dirnamefchdir -- change the working directory for a process via fdchroot -- change the root filesystem for a processCOP 4342Fall 2006 Building blocksModifying the current process’s stateexecve -- execute another binary in this current processfork -- create a new child process running the same binaryclone -- allows the child to share execution context (unlike fork(2))exit -- terminate the current processCOP 4342Fall 2006 Building blocksModifying the current process’s stategetdtablesize -- report how many file descriptors this process can have-- active simultaneouslyCOP 4342Fall 2006 Building blocksModifying the current process’s stategetgid -- return the group id of this processgetuid -- return the user id of this processgetpgid -- return process group id of this processgetpgrp -- return process group’s group of this processCOP 4342Fall 2006 Building blocksModifying the current process’s stategetpid -- return the process id of this processgetppid -- return parent process id of this processgetrlimit -- set a resource limit on this process (core size, cpu time,-- data size, stack size, and others)getrusage -- find amount of resource usage by this processCOP 4342Fall 2006 Building blocksModifying the current process’s statenice -- change the process’s priorityCOP 4342Fall 2006 Building blocksNetworkingsocket -- create a file descriptorbind -- bind a file descriptor to an address, such a tcp portlisten -- specify willingness for some number of connections to


View Full Document

FSU COP 4342 - Building blocks for Unix power tools

Download Building blocks for Unix power tools
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Building blocks for Unix power tools and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Building blocks for Unix power tools 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?