Programmer Interface
- Like most computer systems, UNIX consists of two separable parts:
- Kernel: everything below the system-call interface and above the physical hardware
- Provides file system, CPU scheduling, memory management, and other OS functions through system calls
- Provides file system, CPU scheduling, memory management, and other OS functions through system calls
- Systems programs: use the kernel-supported system calls to provide useful functions, such as compilation and file manipulation
System Calls
- System calls define the programmer interface to UNIX
- The set of systems programs commonly available defines the user interface
- The programmer and user interface define the context that the kernel must support
- Roughly three categories of system calls in UNIX
- File manipulation (same system calls also support device manipulation)
- Process control
- Information manipulation
File Manipulation
- A file is a sequence of bytes; the kernel does not impose a structure on files
- Files are organized in tree-structured directories
- Directories are files that contain information on how to find other files
- Path name: identifies a file by specifying a path through the directory structure to the file
- Absolute path names start at root of file system
- Relative path names start at the current directory
- System calls for basic file manipulation: create, open, read, write, close, unlink, trunc
Process Control
- A process is a program in execution
- Processes are identified by their process identifier, an integer
- Process control system calls
- fork creates a new process
- execve is used after a fork to replace on of the two processes’s virtual memory space with a new program
- exit terminates a process
- A parent may wait for a child process to terminate; wait provides the process id of a terminated child so that the parent can tell which child terminated
- wait3 allows the parent to collect performance statistics about the child
- A zombie process results when the parent of a defunct child process exits before the terminated child
- Processes communicate via pipes; queues of bytes between two processes that are accessed by a file descriptor
- All user processes are descendants of one original process, init
- init forks a getty process: initializes terminal line parameters and passes the user’s login name to login
- login sets the numeric user identifier of the process to that of the user
- executes a shell which forks subprocesses for user commands
- setuid bit sets the effective user identifier of the process to the user identifier of the owner of the file, and leaves the real user identifier as it was
- setuid scheme allows certain processes to have more than ordinary privileges while still being executable by ordinary users
SIGNALS
- Facility for handling exceptional conditions similar to software interrupts
- The interrupt signal, SIGINT, is used to stop a command before that command completes (usually produced by ^C)
- Signal use has expanded beyond dealing with exceptional events
- Start and stop subprocesses on demand
- SIGWINCH informs a process that the window in which output is being displayed has changed size
- Deliver urgent data from network connections
Process Groups
- Set of related processes that cooperate to accomplish a common task
- Only one process group may use a terminal device for I/O at any time
- The foreground job has the attention of the user on the terminal
- Background jobs – nonattached jobs that perform their function without user interaction
- Access to the terminal is controlled by process group signals
- Each job inherits a controlling terminal from its parent
- If the process group of the controlling terminal matches the group of a process, that process is in the foreground
- SIGTTIN or SIGTTOU freezes a background process that attempts to perform I/O; if the user foregrounds that process, SIGCONT indicates that the process can now perform I/O
- SIGSTOP freezes a foreground process
Information Manipulation
- System calls to set and return an interval timer:getitmer/setitmer
- Calls to set and return the current time:gettimeofday/settimeofday
- Processes can ask for
- their process identifier: getpid
- their group identifier: getgid
- the name of the machine on which they are executing: gethostname
Library Routines
- The system-call interface to UNIX is supported and augmented by a large collection of library routines
- Header files provide the definition of complex data structures used in system calls
- Additional library support is provided for mathematical functions, network access, data conversion, etc
User Interface
- Programmers and users mainly deal with already existing systems programs: the needed system calls are embedded within the program and do not need to be obvious to the user
- The most common systems programs are file or directory oriented
- Directory: mkdir, rmdir, cd, pwd
- File: ls, cp, mv, rm
- Other programs relate to editors (e.g., emacs, vi) text formatters (e.g., troff, TEX), and other activities
Shells and Commands
- Shell – the user process which executes programs (also called command interpreter)
- Called a shell, because it surrounds the kernel
- The shell indicates its readiness to accept another command by typing a prompt, and the user types a command on a single line
- A typical command is an executable binary object file
- The shell travels through the search path to find the command file, which is then loaded and executed
- The directories /bin and /usr/bin are almost always in the search path
- Typical search path on a BSD system:
( ./home/prof/avi/bin /usr/local/bin /usr/ucb/bin /usr/bin ) - The shell usually suspends its own execution until the command completes
0 Response to " Unix BSD Part 2 "
Post a Comment