How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes



Similar documents
Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

5. Processes and Memory Management

Lecture 25 Systems Programming Process Control

ELEC 377. Operating Systems. Week 1 Class 3

1 Posix API vs Windows API

Process definition Concurrency Process status Process attributes PROCESES 1.3

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

An Implementation Of Multiprocessor Linux

Leak Check Version 2.1 for Linux TM

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

Operating Systems and Networks

Libmonitor: A Tool for First-Party Monitoring

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Debugging with TotalView

The Linux Kernel: Process Management. CS591 (Spring 2001)

7.2 Examining Processes on the Command Line

Intel P6 Systemprogrammering 2007 Föreläsning 5 P6/Linux Memory System

Chapter 6, The Operating System Machine Level

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

Grundlagen der Betriebssystemprogrammierung

Chapter 14 Virtual Machines

Unix Security Technologies. Pete Markowsky <peterm[at] ccs.neu.edu>

System Calls and Standard I/O

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

System Security Fundamentals

ARUNNING INSTANCE OF A PROGRAM IS CALLED A PROCESS. If you have two

Jorix kernel: real-time scheduling

Shared Address Space Computing: Programming

The System Monitor Handbook. Chris Schlaeger John Tapsell Chris Schlaeger Tobias Koenig

Java Troubleshooting and Performance

Minix Mini Unix (Minix) basically, a UNIX - compatible operating system. Minix is small in size, with microkernel-based design. Minix has been kept

CS420: Operating Systems OS Services & System Calls

Linux Driver Devices. Why, When, Which, How?

Virtual Private Systems for FreeBSD

Real Time Programming: Concepts

Lecture 5. User-Mode Linux. Jeff Dike. November 7, Operating Systems Practical. OSP Lecture 5, UML 1/33

W4118 Operating Systems. Junfeng Yang

CIS 551 / TCOM 401 Computer and Network Security. Spring 2005 Lecture 4

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

Parallelization: Binary Tree Traversal

CS161: Operating Systems

C Programming Review & Productivity Tools

Linux/UNIX System Programming. POSIX Shared Memory. Michael Kerrisk, man7.org c February 2015

Assignment 5: Adding and testing a new system call to Linux kernel

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

OPERATING SYSTEM SERVICES

Operating Systems. Privileged Instructions

CSC 2405: Computer Systems II

Program 5 - Processes and Signals (100 points)

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

SYMANTEC BACKUPEXEC2010 WITH StorTrends

RTOS Debugger for ecos

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

CSE331: Introduction to Networks and Security. Lecture 34 Fall 2006

Security Overview of the Integrity Virtual Machines Architecture

Migration of Process Credentials

COS 318: Operating Systems

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Chapter 3 Operating-System Structures

Object Oriented Software Design II

HP POLYSERVE SOFTWARE

Operating Systems. Design and Implementation. Andrew S. Tanenbaum Melanie Rieback Arno Bakker. Vrije Universiteit Amsterdam

Outline. Operating Systems Design and Implementation. Chap 1 - Overview. What is an OS? 28/10/2014. Introduction

Stack Overflows. Mitchell Adair

LSN 10 Linux Overview

PostgreSQL on Windows

Operating System Tutorial

Example of Standard API

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Lecture 25 Symbian OS

Operating System Structures

This tutorial will take you through step by step approach while learning Operating System concepts.

Sistemi Operativi. Lezione 25: JOS processes (ENVS) Corso: Sistemi Operativi Danilo Bruschi A.A. 2015/2016

Operating Systems. May 15, 2013

Betriebssysteme KU Security

An Introduction to the ARM 7 Architecture

A Comparative Study on Vega-HTTP & Popular Open-source Web-servers

Writing a C-based Client/Server

µtasker Document FTP Client

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

Introduction. What is an Operating System?

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer

CIS 551 / TCOM 401 Computer and Network Security

Threads Scheduling on Linux Operating Systems

A Look through the Android Stack

CISC 181 Project 3 Designing Classes for Bank Accounts

File Systems Management and Examples

C++ INTERVIEW QUESTIONS

CEN 559 Selected Topics in Computer Engineering. Dr. Mostafa H. Dahshan KSU CCIS

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

II. Systems Programming using C (Process Control Subsystem)

Backing Up TestTrack Native Project Databases

Unix System Calls. Dept. CSIE

FAME Operating Systems

Transcription:

Content Introduction and History File I/O The File System Shell Programming Standard Unix Files and Configuration Processes

Programs are instruction sets stored on a permanent medium (e.g. harddisc). Processes are instantiated programs which run in a computer s main memory. Modern operating systems can executed several processes at the same time. By switching quickly between the processes, the OS creates the illusion of parallel process execution. Process switching is done by the so-called scheduler. Process can be in different states: Waiting for input Computing Process activated by scheduler Scheduler chooses different process Blocked Input available Ready

State Computing: Process is currently using the processor. State Ready: Scheduler has suspended the process. The process is waiting to be activated by the scheduler. State Blocked: The process needs some input which is currently not available. To avoid busy waiting the process is deactivated. Waiting for input Computing Process activated by scheduler Scheduler chooses different process Blocked Input available Ready

Waiting for input Computing Process activated by scheduler Scheduler chooses different process Blocked Input available Ready To reactivate a process its previous state must be restored. This includes: the program counter all registers status word stack pointer memory pointers

Process activation and suspension: Registers PC, SC, of Process1 are saved Registers, PC, SC, of Process 2 are restored Process 1 Process 2 The scheduler decides which process is when activated and deactivated. This is the socalled scheduling strategy. time

Each process is described by one so-called Process Control Block (PCB): Dynamic Infos Memory Management File Management Etc. Registers Pointer to Textseg. Root Direc. Priority Programm Counter Pointer to Dataseg. Working Direc. Process ID Program Status Word Pointer to Stackseg. File Descriptor Scheduling Infos Stack Pointer User-ID Parent Process Process State Group-ID Signals Starting Time Next Alarm

src/proc.h: struct proc { struct stackframe_s p_reg; /* process' registers saved in stack frame */ proc_nr_t p_nr; /* number of this process (for fast access) */ struct priv *p_priv; /* system privileges structure */ char p_rts_flags; /* SENDING, RECEIVING, etc. */ char p_misc_flags; /* Flags that do suspend the process */ char p_priority; /* current scheduling priority */ char p_max_priority; /* maximum scheduling priority */ char p_ticks_left; /* number of scheduling ticks left */ char p_quantum_size; /* quantum size in ticks */ struct mem_map p_memmap[nr_local_segs]; /* memory map (T, D, S) */ clock_t p_user_time; /* user time in ticks */ clock_t p_sys_time; /* sys time in ticks */

Unix: 1.fork() creates a copy of the running process 2.loading of new memory image (program), e.g. by calling execve() Windows: 1. CreateProcess() creates new process and loads new program

Unix processes remember their parent process. Since all Unix operating systems first create an initial process named init, every Unix system is essentially a tree of processes with init being the root. init forks off one process for each terminal. Users can log in into each terminal. The shell process than forks off new shells for each command. Windows process are not hierarchically.

Process can end in different ways: self termination termination by means of a serious problem termination by operating system self termination: Unix: call of exit() Windows: call of exitprocess() termination by means of a serious problem: invalid instruction invalid memory address division by zero termination by operating system: Unix: kill() Windows: TerminateProcess()

As mentioned, processes take care of resource and execution control. Sometimes closely related program modules should run in parallel, communicate with each other and use the same resources. So while execution control is needed, resource control is unnecessary and might even hinder the communication, e.g. by preventing shared memory. For such cases, threads were invented. Threads are therefore light-weighted processes which only need some execution information: Dynamic Infos Memory Management File Management Etc. Registers Pointer to Textseg. Root Direc. Priority Programm Counter Pointer to Dataseg. Working Direc. Process ID Program Status Word Pointer to Stackseg. File Descriptor Scheduling Infos Stack Pointer User-ID Parent Process Process State Group-ID Signals Starting Time Next Alarm

A process is instantiated from a program file. When a program is instantiated, first of all a startup code is executed which then jumps into the main function. The program layout is as follows: Command line arguments and env. variables Stack Heap uninitialized data (bss) set to zero by exec Shared libraries are a way for processes to share code. initialized data Text copied from program

Dynamic memory allocation happens on the heap using the functions malloc, calloc, and realloc. free is used to free the memory. Assignment: 1) Write a C program which allocates some memory, uses it to store a string, and frees the memory again.

Creation of a new process Process ID = 41. id = fork(); id == 42. Process ID = 42. id = fork(); id == 0. The child process is a copy of the parent process, i.e. data, bss, and heap, stack segments are copied. Both share the same text segment. #include <unistd.h> All user ID/Group ID, terminals, directories, etc. are also copied. pid_t fork(void); Parent process: Process ID of child process. Child process: 0

#include <unistd.h> pid_t getpid(void); pid_t getppid(void); // Returns process ID // Returns parent s process ID #include <stdlib.h> void exit(int statue); void abort(void); // Finishes process // Aborts a process #include <sys/wait.h> pid_t wait(int *statloc); // Waits for a child process // to finish, returns child process ID pid_t waitpid(pid_t pid, int *statloc, int options); // pid>0: Waits for the child process pid to finish, // pid==0: Waits for a child process with the same group // process ID to finish, // pid<-1: Wait for a child process with the group process ID // pid to finish

After the fork(), the child process usually changes its program image: #include <unistd.h> extern char **environ; int execl(const char *path, const char *arg0,... /*, (char *)0 */); int execle(const char *path, const char *arg0,... /*, (char *)0, char *const envp[] */); int execlp(const char *file, const char *arg0,... /*, (char *)0 */); int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); int execvp(const char *file, const char *search_path, char *const argv[]);