Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
127 views

Lecture2 Introduction To Linux

Here are the answers to the exercises: EXERCISE 2.1: #include <stdio.h> #include <unistd.h> int main() { printf("My PID is: %d\n", getpid()); printf("My PPID is: %d\n", getppid()); return 0; } EXERCISE 2.2: To assure that the parent process is not present when the child calls getppid, we can have the parent exit immediately after forking the child. The child will then call getppid and it will return 1, since the init process (PID 1) becomes the parent of orphaned

Uploaded by

Sarah Hassan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Lecture2 Introduction To Linux

Here are the answers to the exercises: EXERCISE 2.1: #include <stdio.h> #include <unistd.h> int main() { printf("My PID is: %d\n", getpid()); printf("My PPID is: %d\n", getppid()); return 0; } EXERCISE 2.2: To assure that the parent process is not present when the child calls getppid, we can have the parent exit immediately after forking the child. The child will then call getppid and it will return 1, since the init process (PID 1) becomes the parent of orphaned

Uploaded by

Sarah Hassan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CS503 Advanced Operating Systems

Lecture No. 2
By Dr. Anwar M. Mirza
Date: August 13, 2009

An Introduction to Linux
Some Facts and Figures:

It is generally said in the OS community that there are more flavors of Unix than most
brands of ice cream! “Linux” belongs to this large family of Unix-like operating systems
such as:

1. AT&T’s System 5 Release 4 (SVR4) Bell Telephone Labs (BTL).


2. University of California’s “Berkeley Software Distribution”. (4.x BSD)
3. Carnegie-Mellon University’s “Mach”.
4. Digital Equipment Corporation’s (DEC) (now COMPAQ) “Digital Unix”.
5. Sun Microsystem’s “Solaris” or “SunOS”.
6. Hewlett-Packard Corporation’s HP-UNIX.
7. Santa Cruz Operation’s SCO-UNIX.
8. Microsoft Corporation and SCO collaborative XENIX for Intel’s 8086
Family.
9. IBM’s AIX.

Linux was initially developed by “Linus Trovalds” in 1991.

 His main aim was to develop a Unix like operating system for IBM compatible
Personal Computers based on Intel’s 80386 microprocessor.
 Linux is now available on other architectures including DEC-Alpha, Sun-SPARC,
Motorola MC680X0, Apple’s PowerPC and IBM’s system/390.

Most Appealing Benefits of Linux:

 It is not a “Commercial Operating System”.


 Its source code is available to anyone to study.
 You can download it from: “http://www.kernel.org” or check your Linux CD for
the source code.

Linux offers the following advantages over its commercial competitors.

1. Linux is free
You can install a complete Unix system at no expense. (Other than the
hardware of course”).
2. Linux is fully customizable in all its components.
You are allowed to freely read and modify the source code of the Kernel and
of all system programs.
3. Linux runs on low-end, cheap hardware platforms
You can even build a network server using an old Intel 80386 with 4MB
RAM.
4. Linux is powerful
Linux systems are very fast, since they fully exploit the features of the
hardware components.
5. Linux has a high standard for source code quality
Linux systems are usually “very stable”; they have a “low failure rate” and
“low system maintenance time”.
6. The Linux Kernel can be very small and compact
Indeed, it is possible t fit both a Kernel image and full root file system
including all fundamental system programs on just one 1.4 MB floppy disk!
None of other commercial Unix variants is able to boot from a single floppy
disk.
7. Linux is highly compatible with many common operating systems
 It lets us mount file systems from all versions of MS DOS and MS
WINDOWS, SVR4, OS2, MacOS, Solaris, SunOS, BSD etc.
 It is able to operate with many network layers like Ethernet, IBM’s
Token ring etc.
 By using suitable libraries, Linux systems are even able to directly run
programs written for other operating systems (like MS DOS, MS
WINDOWS, SVR3 and SVR4, 4.4BSD, SCO Unix, XENIX etc for
Intel’s 80x86 platform).

8. Linux is well-supported
It is lot easier to get patches and updates for Linux than for any other
proprietary operating system.

Level of Description:

 The complete source code for all supported architectures is


1. Contained in about 4500 C and Assembly files
2. Stored in about 270 subdirectories.
3. Consists of about 2 million lines of code.
4. Which occupies more than 58MB space.

 The textbooks referred to in this course do not (in fact cannot possible) cover
all lines of this code. Dozens of books will indeed be required, simply to show
all lines of this code.
 We will try to cover only few MB of this code------ to get to know the
essentials of how Linux works!
PROCESSING ENVIRONMENT:

 All processes have a processing environment in Linux.


 It consists of a “current state of the system” and by the “parent process”.
 Processes have attributes or characteristics that identify them and define their
behavior. Some important attributes are:

1. Process Identifiers e.g. Process ID, Parent Process ID


2. User Information.
3. Processing Time
4. Resource Usage.
5. Process Groups and sessions.

We briefly describe them here.

1. PROCESS IDENTIFIERS:

(a) Process ID (PID):


 Associated with each process is a “unique positive integer” identification
number called process ID (PID).
 Process IDs are allocated sequentially.
 When a system is booted, a few system processes, which are initiated only
once, will always be assigned the same unique process ID.

Examples are:
PID BSD Unix Solaris Red Hat Linux
0 “Swapper” “Sched” ??????
process responsible Process
for scheduling

1 “init” “init” “init”


process manages Process Process
terminal lines.
parent of all other
process
2 “pagedaemon” “pageout” “keventd”
responsible for Process
paging

 Processes are assigned free PIDs of increasing value until the maximum
system value for a process ID is reached.
 When the maximum value of PID has been assigned, the system wraps around
and begins to use lower process IDs that are not currently used.
 The system call getpid is used to obtain PID. Declared in the system header
file <unistd.h>, the prototype of getpid is
pid_t getpid(void);
b) PARENT PROCESS ID (PPID):

 Every process has an associated parent process ID (PPID).


 Parent process is the process that forked the child process.
 The parent process ID can be obtained using the system call getppid. Its
prototype in <unistd.h> is
pid_t getppid (void);

c) PROCESS GROUP ID:

 Every process belongs to a process group that is identified by an integer


process group ID.
 When a process generates child processes, the operating system will
automatically create a process group.
 The initial parent process is known as the “process leader”.
 The process leader’s process ID will be the same as its process group ID.
 Additional process group members generated by the process group leader
inherit the same process ID.
 The OS uses process group relationships to “distribute signals” to groups of
processes.

For example, should a process group leader receive a “kill” or “hang-up” signal
causing it to terminate, then all processes in its group will also be passed the same
terminating signal.

 A process can find its process group ID from the system call getpgid.
Its prototype in <unistd.h> is :
pid_t getpgid(pid_t pid);

 See what this program does?

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

void main (void) {


int i;
printf(“\n\n Initial process \t PID %6d\t PPID
%6d \t GID %6d \n\n”, getpid() , getppid(),
getpgid(0));
for ( i=0 ; i<3 ;++i)
if (fork( )= = 0)
printf(“New Process\t\t PID %6d \t PPID
%6d\t GID %6d \n”, getpid(), getppid(),
getgpid(0) );
}
EXERCISE 2.1:
Write down a gcc program that returns to you its, and its parent IDs.

EXERCISE 2.2
The manual page entry for the getppid system call does not specially indicate
what is returned by getppid if the parent process is no longer present when the
getppid call is made. Write a program that displays the value returned by getppid
when such an event occurs (the parent predeceases the child). How did you assure that
the parent was not present when the child process made its getppid call?

You might also like