Process Concepts:Case Study,UNIX Processes

Case Study: UNIX Processes

UNIX and UNIX-based operating systems provide an implementation of processes that has been borrowed by many other operating systems (see the Mini Case Study, UNIX Systems). In this section, we describe the structure of UNIX processes, discuss several UNIX features that motivate the discussion in the following chapters and introduce how UNIX allows users to perform process management operations.

Each process must store its code, data and stack in memory during execution. In a real memory system, processes would locate such information by referencing a range of physical addresses. The range of valid main memory addresses for each process is determined by the size of main memory and the memory consumed by other processes. Because UNIX implements virtual memory, all UNIX processes are provided with a set of memory addresses, called a virtual address space, in which the process may store information. The virtual address space contains a text region, data region and stack region.40

The kernel maintains a process’s PCB in a protected region of memory that user processes cannot access. In UNIX systems,a PCB stores information including the contents of processor registers, the process identifier (PID), the program counter and the system stack.41, 42 The PCBs for all processes are listed in the pro- cess table, which allows the operating system to access information (e.g., priority) regarding every process.43

UNIX processes interact with the operating system via system calls. Figure 3.10 lists several of these.A process can spawn a child process by using the fork system call, which creates a copy of the parent process.44, 45 The child process receives a copy of the parent process’s data and stack segments and any other resources.46, 47 The text segment, which contains the parent’s read-only instructions, is shared with its child. Immediately following the fork, the parent and child pro- cess contain identical data and instructions. This means that the two processes must perform exactly the same actions unless either the parent or child can determine its identity. The fork system call therefore returns different values; the parent process

Mini Case Study

UNIX Systems

In the days before Windows, Macintosh, Linux or even DOS, operating systems typically worked on only one model of computer, managing system resources, running batch streams and little more.48 From 1965 to 1969, a

group of research teams from Bell Laboratories, General Electric and Project MAC at MIT developed the Multics operating system—a general-purpose computer utility, designed to be “all things to all people.”49 It was large, expensive and complex. In 1969, Bell Labs withdrew from the project and their own small team, led by Ken Thompson, began designing a more practical operating system to run machines at Bell Labs. (Continued on the next page.)

Mini Case Study

UNIX Systems (Cont.)

Thompson implemented the basic components of the operating sys- tem, which Brian Kernighan named UNICS, a joke on the “multi” aspect of Multics; the spelling eventually changed to UNIX. Over the next few years, UNIX was rewritten in an interpreted implementation of Thompson's language B (based on Martin Richard’s BCPL programming language), and soon after in Dennis Ritchie's faster, compiled C language.50

Due to a federal anti-trust lawsuit, AT&T (which owned Bell Labs) was not allowed to sell computer products, so they distributed UNIX source code to universities for a small fee to cover just the expense of producing the magnetic tapes. A group of students at the University of California at Berkeley, led by Bill Joy (later a cofounder of Sun Microsystems), modified the UNIX source code, evolving the operating system into what became known as Berkeley Software Distribution UNIX (BSD UNIX).51

Industry software developers were drawn to UNIX because it was free, small and customize-

able. To work with UNIX, developers had to learn C, and they liked it. Many of these developers also taught in colleges, and C gradually replaced Pascal as the preferred teaching language in college programming courses. Sun Microsystems based its SunOS on BSD UNIX, then later teamed up with AT&T to design the Solaris operating system based on AT&T’s System V Release 4 UNIX.52 A group of other UNIX developers, concerned that Sun's association with AT&T would give Sun an unfair business lead over other UNIX developers, formed the Open Software Foundation (OSF) to produce their own non- proprietary version of UNIX called OSF/1; the fierce competition between OSF and AT&T-backed Sun was dubbed the UNIX Wars.53

Several important operating systems are based on UNIX technology. Professor Andrew Tanenbaum of the Vrije Universiteit in Amsterdam built Minix in 1987, a stripped-down version of UNIX that was designed for teaching OS basics and is still used for this purpose in some college courses. Linus Torvalds, a Finnish graduate student, used Minix to begin writing the well-known open-source Linux operating sys- tem—now a whole family of systems in its own right (see Chapter 20, Case Study: Linux).54 Linux is the most popular open- source operating system, and companies including IBM, Hewlett-Packard, Sun Microsystems and Intel all offer Linux ver- sions as an operating system option for their servers. OpenBSD is another open-source project, led by Theo de Raadt, and is rec- ognized as the most secure operating system available (see Chapter 19, Security).55, 56, 57, 58 FreeBSD is also open-source and is known for its ease of use.59 Yet another BSD descendant, Net- BSD, has focused on portability to a variety of systems.60, 61 IBM's AIX, based on both System V and

BSD,62 runs on some of IBM’s servers. IBM claims AIX has a high degree of source-code compatibility with Linux.63 Hewlett-Pack- ard's HP-UX is becoming a strong competitor to AIX and Solaris, achieving the highest ratings in all the categories in a 2002 D.H. Brown Associates report, placing ahead of both Solaris and AIX.64, 65, 66

receives the PID of the child and the child process receives a value of zero. This convention allows the child process to recognize that it is newly created. Application programmers can use this convention to specify new instructions for the child process to execute.

A process can call exec to load a new program from a file; exec is often per- formed by a child process immediately after it is spawned.67 When the parent creates a child process, the parent can issue a wait system call, which blocks the parent until the specified child process terminates.68 After a process has completed its work, it issues the exit system call. This tells the kernel that the process has finished; the kernel responds by freeing all of the process’s memory and other resources, such as open files. When a parent process exits, its child processes are typically relocated in the process hierarchy to be children of the init process.69, 70 If a parent process is terminated by a kill signal from another process, that signal is also sent to its child processes.

UNIX process priorities are integers between –20 and 19 (inclusive) that the system uses to determine which process will run next. A lower numerical priority value indicates a higher scheduling priority.71 Processes that belong to the operating system, called kernel processes, often have negative integer values and typically have higher scheduling priority than user processes.72 Operating system processes that perform maintenance operations periodically, called daemons, typically exe- cute with the lowest possible priority.

Many applications require several independent components to communicate during execution, requiring interprocess communication (IPC). UNIX provides several mechanisms to enable processes to exchange data, such as signals and pipes (see Section 3.5, Interprocess Communication, and Section 20.10.2, Pipes).73

image

Self Review

1. Why can a parent and its child share the parent’s text segment after a fork system call?

2. Why must a process use IPC to share data with other processes?

Ans: 1) The text segment contains instructions that cannot be modified by either process, meaning that both the parent and child process will execute the same instructions regardless of whether the operating system maintains one, or multiple, copies of the segment in memory. Therefore, the operating system can reduce memory consumption by sharing access to the text region between a parent and its child. 2) The operating system does not allow unrelated processes to share the data segment of their address spaces, meaning that data stored by one process is inaccessible to an unrelated process. Therefore, the operating system must pro- vide some mechanism to make data from one process available to another.

Comments

Popular posts from this blog

Input Output (IO) Management:HW/SW Interface and Management of Buffers.

Introduction to Operating Systems:Early History: The 1940s and 1950s

Input Output (IO) Management:IO Organization.