Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,

Slides:



Advertisements
Similar presentations
Recitation 8: 10/28/02 Outline Processes Signals –Racing Hazard –Reaping Children Annie Luo Office Hours: Thursday 6:00.
Advertisements

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Using tcpdump. tcpdump is a powerful tool that allows us to sniff network packets and make some statistical analysis out of those dumps. tcpdump operates.
Introduction to Unix – CS 21 Lecture 10. Lecture Overview Midterm questions Jobs and processes description The foreground and background Controlling jobs.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
Signals Hua LiSystems ProgrammingCS2690Signals. Topics: Sending Signals -- kill(), raise() Signal Handling -- signal() sig_talk.c -- complete example.
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.
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
CSSE Operating Systems
Processes & Daemons Chapter IV / Part III. Commands Internal commands: alias, cd, echo, pwd, time External commands, code is in a file: grep, ls, more.
B. RAMAMURTHY Pag e 1 Task Control: Signals and Alarms Chapter 7 and 8 7/2/2015.
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
COMP5102 Lecture 4 Operating Systems (OS) Inter-process Communication phones off (please)
University of Pennsylvania 9/12/00CSE 3801 Multiprogramming CSE 380 Lecture Note 3.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Operating Systems Yasir Kiani. 22-Sep Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread.
Introduction to Processes CS Intoduction to Operating Systems.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
The process concept (section 3.1, 3.3 and demos)  Process: An entity capable of requesting and using computer resources (memory, CPU cycles, files, etc).
Linux+ Guide to Linux Certification, Third Edition
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Creating and Executing Processes
The kernel considers each program running on your system to be a process A process lives as it executes, with a lifetime that may be short or long A process.
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
System calls for Process management
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Operating Systems Process Creation
CS4315A. Berrached:CMS:UHD1 Process Management Chapter 6.
Signals and Signal Processing CIS 370 Lab 7 Umass Dartmouth.
Outline for Today Objectives –Finish discussion of Birrell –UNIX Signals –Eraser Administrative –Spider talk after class.
Signals (Chap 10 in the book “Advanced Programming in the UNIX Environment”) Acknowledgement : Prof. Y. Moon at Kangwon Nat’l Univ.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Operating Systems Recitation 4, April th, 2002 Signals.
Signals. Introduction r A signal is a mechanism for notifying a process that an event has occurred. m When a signal is sent to a process is normal execution.
© 숙대 창병모 1 제 10 장 신호 (Signal). © 숙대 창병모 2 Contents 1. Signal Concepts 2. signal() 3. Interrupted System Calls 4. kill() /raise() 5. alarm() pause() 6.
Process Management Azzam Mourad COEN 346.
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
System calls for Process management Process creation, termination, waiting.
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
UNIX signals.
...looking a bit closer under the hood
Task Control: Signals and Alarms Chapter 7 and 8
Unix Process Management
CSC Advanced Unix Programming, Fall 2015
Operating Systems Lecture 12.
Inter-Process Communication ENCE 360
Process Management and System Monitoring
Process Description and Control in Unix
Process Description and Control in Unix
System Programming: Process Management
Presentation transcript:

Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork, wait, waitpid) Examples  Working with Signals: Purpose Commands (signal, pause, raise, sigaction) Examples

Processes  A process is the memory space and settings with which a program runs.  Data and programs are stored in files on the disk and programs run in processes. File System / bin etc home UNIX OS Memory (User Space)Hard Disk Process (PID#): Stores running program & related data

Processes  There are many processes that run in the Unix OS:  Upon Unix OS startup, the Kernel runs and spawns the basic processes (sched, init, bdflush, vhand).  The init processes spawns or “creates” many other processes including:  bcheckrc (check for “dirty” filesystem – runs fsck to clean)  rc2.d or rc3.c (Depending on run-level specified) – this causes many scripts (processes) to run when starting up (rc simply stands for “run control”)  getty (used to set the terminal type, speed & line discipline of terminal connection). Getty process also prompts user to enter username & password, and when entered runs the login process to validate the user, that allows the shell process to run and set up the user’s environment.

Processes Once the user has logged into their account and is running a shell, the user issues commands to spawn other processes (programs such as executable files, shell scripts, etc…) Memory is divided between Kernel Space and User Space. Processes “live” in user space which is the portion of computer memory that holds running programs and their data. In order to spawn these processes, the shell must use the fork() system call to create another process in order to run the program. The state diagram in the next slide demonstrates how new processes are spawned from the user’s shell.

Unix Process – State Diagram

Managing Processes  Managing process is similar to managing files & directories: Can set attributes of processes (niceness level) Can “hide” processes in background (ctrl-z, &, bg, fg) Can identify processes by ID # ($$) Can create and remove processes (fork, kill) Can list process information using ps command Excess number of running processes can reduce system performance (eg. Internet worms, viruses)

Managing Processes  ps command Used to display process information. By default (no arguments) will only display basic information of user’s processes. Other options: -ashow all processes connected to tty -xshow processes no connected to tty (eg. background) -eshow all processes -ffull listing -llong listing -uuser-oriented format Popular ps command combinations: ps –la ps -aux

Running Program in Same Process In shell scripting, programs can be run in same process by using exec command. In a C program, the system() call can be used (eg. system(“ls”);) but is considered inefficient because another process is created in a shell to run command. The exec system call is used to run programs or commands within the same process. There is no actual exec system call, but a series of specific exec system calls: Execl, execlp, execle, execv, execvp, execve

Running Program in Same Process  execl – requires pathname to program, # number of arguments ending with a null pointer.  execlp – need only program name (no full pathname), plus number of arguments ending with a null pointer.  execle – same as execl, but can also pass a new program environment.  execv – requires pathname to program, plus an array of strings containing arguments.  execvp – need only program name, plus an array of strings containing arguments.  exece – same as execv except can also pass a new program environment. You can view programming examples in Sigma at: ~msaul/unx511/processes

Processes  Problem with using exec:  Running exec is placed into the current process thus replacing the code and data of that process – when exec is finished, process is terminated and returned to shell prompt.  What if we want to keep code & data of current process after running exec?  Solution: Use fork to create a copy of the parent process and instruct parent process to wait until child process to complete to execute the remaining tasks. Refer to example execlp_fork.c in ~msaul/unx511/processes (try issuing execlp_fork | more - what happens?)

Processes  System Calls: fork() Creates a child process. Zero represents the child process and fork will return the PID of the child process. wait() “Blocks” the parent process until a child process finishes (i.e. parent process is blocked until a child process calls exit ). Wait will also return the value of the finished child process. waitpid() “blocks” the parent process until a specific child has finished, or run parent process without child to finish, but check on status of child process exiting.

Processes  Zombie Processes When a child process dies and calls exit, various operations are run to de-allocate memory assigned to the process, close open files, and frees all data structures. The kernel store the exit message from the child process to be used by the parent (in case it has called wait and is waiting for the child process to exit). A process that has died but has an uncollected exit value is called a zombie process. This can happen in poorly designed programs that don’t wait long enough to “mop-up” all terminated processes Refer to example x in ~msaul/unx511/signals directory

Signals A signal in terms of Unix represents an event message. Signals that are caused by a process (such as dividing by zero) are referred to as synchronous signals. Signals that are caused by events outside the process (like the user pressing CTRL C) are called asynchronous signals. Asynchronous signals go to ALL attached processes. Signals can be numbered, or assigned names (for example, signal #9 or signal name SIGKILL represents the KILL PROCESS signal)

Signals  Types: Signal Name(Signal #)  SIGABRT(6) - Process Abort (CTRL \) SIGINT(2) - Interrupt (CTRL C) SIGCHLD(20) - Child process has stopped or exited. SIGSTOP(19) - Stop executing (CTRL Z can’t be ignored ) SIGALRM(14) - Alarm Clock SIGFPE(8) - Floating Point Exception SIGHUP(1) - Hang-up SIGILL(4) - Illegal Instruction SIGKILL(9) - Kill Process (cannot be ignored) SIGPIPE(13) - Write on pipe with no reader SIGQUIT(3) - Terminal Quit SIGSEGV(11) - Invalid memory segment access SIGTERM(15) - Termination SIGUSR1(30) - User-defined Signal 1 SIGUSR2(31) - User-defined Signal 2 Issue command kill –l for a full listing or try man 7 signal for more info.

Signals – System calls  signal() Used to allow process to instruct Kernel how to respond to the signal. For example, signal(SIGINT, SIG_IGN) instructs the Kernel to ignore the interrupt signal (eg ignore CTRL C ). The first parameter is the signal, and the second parameter is the instruction. Another instruction can be SIG_DFL which means to restore the default action of the signal (like SIGINT – CTRL C would then interrupt). An instruction can also be a function name (like returning to canonical mode, etc… when pressing CTRL C).

Signals – System calls  pause() Can be used to suspend (block) execution until a specific signal occurs. For example, pause(SIGINT)  raise() Can be used to generate or “raise” a signal. For Example, raise(SIGALRM), raise(SIGKILL), etc…

Signals – System calls kill(pid,signal) Used to allow processes to terminate and send signals to other processes. Any signal can be sent via the kill command. Eg. kill(getpid(),SIGARLM), kill(getppid(),SIGTERM), etc… sigaction() A “newer” system call designed to replace “signal” system call (although most programs use “signal”). Refer (in Sigma) to ~msaul/unx511/signals directory for examples involving these system calls involving signals