Genesis: From Raw Hardware to Processes Andy Wang Operating Systems COP 4610 / CGS 5765.

Slides:



Advertisements
Similar presentations
Genesis: from raw hardware to processes System booting sequence: how does a machine come into life.
Advertisements

Chapter 9: Understanding System Initialization The Complete Guide To Linux System Administration.
Linux+ Guide to Linux Certification Chapter Nine System Initialization.
Linux Booting Procedure
Linux can be generally divided into four major components: 1. KERNEL – OS, ultimate boss The kernel is the core program that runs programs and manages.
Startup. Major phases  BIOS  MBR program  Boot loader (Partition boot program )  OS’s kernel Loader  CPU always starts running at x’FFFF0’=1,048,560.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
1 Processes Professor Jennifer Rexford
Processes CSCI 444/544 Operating Systems Fall 2008.
Introduction to Kernel
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Computer System Organization S H Srinivasan
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Processes and Resources
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Linux Booting Procedure
System Calls 1.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Booting. Booting is the process of powering it on and starting the operating system. power on your machine, and in a few minutes your computer will be.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Processes: program + execution state
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
CE Operating Systems Lecture 10 Processes and process management in Linux.
System calls for Process management
© 2004, D. J. Foreman 1 Implementing Processes and Threads.
Operating Systems Process Creation
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Copyright © Genetic Computer School 2008 Computer Systems Architecture SA 8- 0 Lesson 8 Secondary Management.
System calls for Process management Process creation, termination, waiting.
MINIX Presented by: Clinton Morse, Joseph Paetz, Theresa Sullivan, and Angela Volk.
System initialization Unit objectives A.Outline steps necessary to boot a Linux system, configure LILO and GRUB boot loaders, and dual boot Linux with.
OS Boot Sequence and File System (implication to “Boot Sector Viruses”) Department of Computer Science Southern Illinois University Edwardsville Spring,
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
Overview A) Power on or reset B) 1st stage boot loader C) 2nd stage boot loader D) Operate system.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Introduction to Operating Systems Concepts
Introduction to Kernel
Protection of System Resources
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
Processes in Unix, Linux, and Windows
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
Genesis: From Raw Hardware to Processes
SUSE Linux Enterprise Desktop Administration
Modern PC operating systems
Lecture 6: Multiprogramming and Context Switching
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
OS Boot Sequence and File System
OS Boot Sequence and File System
Intro to the Shell with Fork, Exec, Wait
Lecture 10 review Booting sequence in Brief
Presentation transcript:

Genesis: From Raw Hardware to Processes Andy Wang Operating Systems COP 4610 / CGS 5765

How is the first process created? What happens when you turn on a computer? How to get from raw hardware to the first running process, or process 1 under UNIX? Well…it’s a long story… It starts with a simple computing machine

Long, Long, Long Ago…(during the 1940s) John von Neumann invented von Neumann computer architecture A CPU A memory unit I/O devices (e.g., disks and tapes)

In von Neumann Architecture, Programs are stored on storage devices Programs are copied into memory for execution CPU reads each instruction in the program and executes accordingly

A Simple CPU Model Fetch-execute algorithm During a boot sequence, the program counter (PC) is loaded with the address of the first instruction The instruction register (IR) is loaded with the instruction from the address

Fetch-Execute Algorithm … … load r4, c load r3, b Memory addresses PC IR 3000 load r3, b PC =

Fetch-Execute Algorithm … … load r4, c load r3, b Memory addresses PC IR 3000 load r3, b while (not halt) { // increment PC

Fetch-Execute Algorithm … … load r4, c load r3, b Memory addresses PC IR 3004 load r3, b while (not halt) { // increment PC // execute(IR)

Fetch-Execute Algorithm … … load r4, c load r3, b Memory addresses PC IR 3004 while (not halt) { // increment PC // execute(IR) load r4, c // IR = memory // content of PC }

Booting Sequence The address of the first instruction is fixed It is stored in read-only-memory (ROM)

Booting Procedure for i386 Machines On i386 machines, ROM stores a Basic Input/Output System (BIOS) BIOS contains information on how to access storage devices

BIOS Code Performs Power-On Self Test (POST) Checks memory and devices for their presence and correct operations During this time, you will hear memory counting, which consists of noises from the hard drive and CDROM, followed by a final beep

After the POST The master boot record (MBR) is loaded from the boot device (configured in BIOS) The MBR is stored at the first logical sector of the boot device (e.g., a hard drive) that Fits into a single 512-byte disk sector (boot sector) Describes the physical layout of the disk (e.g., number of tracks)

After Getting the Info on the Boot Device BIOS loads a more sophisticated loader from other sectors on disk The more sophisticated loader loads the operating system

Operating System Loaders Under old Linux, this sophisticated loader is called LILO (Linux Loader) It has nothing to do with Lilo and Stitch Linux uses GRUB (GRand Unified Bootloader) nowadays

More on OS Loaders LILO Is partly stored in MBR with the disk partition table A user can specify which disk partition and OS image to boot Windows loader assumes only one bootable disk partition After loading the kernel image, LILO sets the kernel mode and jumps to the entry point of an operating system

Booting Sequence in Brief A CPU jumps to a fixed address in ROM, Loads the BIOS, Performs POST, Loads MBR from the boot device, Loads an OS loader, Loads the kernel image, Sets the kernel mode, and Jumps to the OS entry point.

Linux Initialization Set up a number of things: Trap table Interrupt handlers Scheduler Clock Kernel modules … Process manager

Process 1 Is instantiated from the init program Is the ancestor of all processes Controls transitions between runlevels Executes startup and shutdown scripts for each runlevel

Runlevels Level 0: shutdown Level 1: single-user Level 2: multi-user (without network file system) Level 3: full multi-user Level 5: X11 Level 6: reboot

Process Creation Via the fork system call family Before we discuss process creation, a few words on system calls…

System Calls System calls allow processes running at the user mode to access kernel functions that run under the kernel mode Prevent processes from doing bad things, such as Halting the entire operating system Modifying the MBR

UNIX System Calls Implemented through the trap instruction trap set kernel mode branch table trusted code user levelkernel level

A fork Example, Nag.c #include int main() { pid_t pid; if ((pid = fork()) == 0) { while (1) { printf(“child’s return value %d: I want to play…\n”, pid); } } else { while (1) { printf(“parent’s return value %d: After the project…\n”, pid); } return 0; } Parent process

A fork Example, Nag.c #include int main() { pid_t pid; if ((pid = fork()) == 0) { while (1) { printf(“child’s return value %d: I want to play…\n”, pid); } } else { while (1) { printf(“parent’s return value %d: After the project…\n”, pid); } return 0; } Parent process

A fork Example, Nag.c #include int main() { pid_t pid; if ((pid = fork()) == 0) { while (1) { printf(“child’s return value %d: I want to play…\n”, pid); } } else { while (1) { printf(“parent’s return value %d: After the project…\n”, pid); } return 0; } Parent process #include int main() { pid_t pid; if ((pid = fork()) == 0) { while (1) { printf(“child’s return value %d: I want to play…\n”, pid); } } else { while (1) { printf(“parent’s return value %d: After the project…\n”, pid); } return 0; } Child process

A fork Example, Nag.c #include int main() { pid_t pid; if ((pid = 3128) == 0) { while (1) { printf(“child’s return value %d: I want to play…\n”, pid); } } else { while (1) { printf(“parent’s return value %d: After the project…\n”, pid); } return 0; } Parent process #include int main() { pid_t pid; if ((pid = 0) == 0) { while (1) { printf(“child’s return value %d: I want to play…\n”, pid); } } else { while (1) { printf(“parent’s return value %d: After the project…\n”, pid); } return 0; } Child process

A fork Example, Nag.c #include int main() { pid_t pid; if ((pid = 3128) == 0) { while (1) { printf(“child’s return value %d: I want to play…\n”, pid); } } else { while (1) { printf(“parent’s return value %d: After the project…\n”, pid); } return 0; } Parent process #include int main() { pid_t pid; if ((pid = 0) == 0) { while (1) { printf(“child’s return value %d: I want to play…\n”, pid); } } else { while (1) { printf(“parent’s return value %d: After the project…\n”, pid); } return 0; } Child process

Nag.c Outputs >a.out child’s return value 0: I want to play… …// context switch parent’s return value 3218: After the project… …// context switch child’s return value 0: I want to play… ^C >

Why clone a process? Simplifies parameter passing Environmental variables, permissions, etc. Performance optimization Copy on write

The exec System Call Family A fork by itself is not interesting To make a process run a program that is different from the parent process, you need exec system call exec starts a program by overwriting the current process

A exec Example, HungryEyes.c #include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); return 0; // should not be reached } A process At a shell prompt: >whereis xeyes /usr/X11R6/bin/xeyes

A exec Example, HungryEyes.c #include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); return 0; // should not be reached } A process

A exec Example, HungryEyes.c #include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); return 0; // should not be reached } A process

A exec Example, HungryEyes.c #include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); return 0; // should not be reached } A process

A exec Example, HungryEyes.c #include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); return 0; // should not be reached } A process

A exec Example, HungryEyes.c #include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); return 0; // should not be reached } A process

A exec Example, HungryEyes.c #include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); return(0); // should not be reached } A process

A exec Example, HungryEyes.c #include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); return(0); // should not be reached } A process

#include #define LB_SIZE 1024 int main(int argc, char *argv[]) { char fullPathName[] = “/usr/X11R6/bin/xeyes”; char *myArgv[LB_SIZE]; // an array of pointers myArgv[0] = (char *) malloc(strlen(fullPathName) + 1); strcpy(myArgv[0], fullPathName); myArgv[1] = NULL; // last element should be a NULL pointer execvp(fullPathName, myArgv); exit(0); // should not be reached } A process A exec Example, HungryEyes.c

Thread Creation Use pthread_create() instead of fork() A newly created thread will share the address space of the current process and all resources (e.g., open files) + Efficient sharing of states - Potential corruptions by a misbehaving thread