Operating Systems Yasir Kiani. 20-Sep-20062 Agenda for Today Review of previous lecture Use of FIFOs in a program Example code Process management commands.

Slides:



Advertisements
Similar presentations
CMP320 Operating Systems Lecture 07, 08 Operating System Concepts
Advertisements

June 1, 1999Foreground/Background Processing1 Introduction to UNIX H. Foreground/Background Processing.
Chapter 5 Controlling Processes Xiaoli Jiao 6/8/99.
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.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process A process is.
Processes and Job Control. Foreground and Background (1)  Unix is a multi-tasking operating system –some of these tasks are being done by other users.
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.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
Controlling Processes & Periodic Processes WeeSan Lee
Linux+ Guide to Linux Certification, Second Edition
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Processes & Daemons Chapter IV / Part III. Commands Internal commands: alias, cd, echo, pwd, time External commands, code is in a file: grep, ls, more.
Process Scheduling. Process The activation of a program. Can have multiple processes of a program Entities associated with a process –Instruction pointer,
CS 497C – Introduction to UNIX Lecture 27: - The Process Chin-Chih Chang
Today’s topic Inter-process communication with pipes.
Hjemmeeksamen 1 INF3190. Oppgave Develop a monitoring/administration tool which allows an administrator to use a client to monitor all processes running.
5 UNIX Processes. Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals.
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 Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
UNIX System Administration Handbook Chapter 4. Controlling Processes 3 rd Edition Evi Nemeth et al. Li Song CMSC691X Summer 2002.
Operating Systems Yasir Kiani. 22-Sep Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread.
Prime View, Inc.1. 2 Chapter Objectives · In this chapter, you will learn about: · Command history · Output redirection and pipes · Filename metacharacters.
Managing Processes CSCI N321 – System and Network Administration Copyright © 2000, 2011 by Scott Orr and the Trustees of Indiana University.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Linux+ Guide to Linux Certification, Third Edition
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Process Control. Module 11 Process Control ♦ Introduction ► A process is a running occurrence of a program, including all variables and other conditions.
Chapter 6 UNIX Special Files Source: Robbins and Robbins, UNIX Systems Programming, Prentice Hall, 2003.
Managing processes and services. 1. How Linux handles processes 2. Managing running processes 3. Scheduling processes.
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
Lecture – Performance Performance management on UNIX.
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.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Guide To UNIX Using Linux Third Edition Chapter 8: Exploring the UNIX/Linux Utilities.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes.
Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Processes.
Interprocess Communication Anonymous Pipes Named Pipes (FIFOs) popen() / pclose()
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Commands C151 Multi-User Operating Systems.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 9 Working.
System Administration. Logging in as System Administrator System Admin login (aka superuser, aka root) –login id: root –Default PS1 prompt: # –Home directory:
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop VI Scheduling & Process Management Professional.
CSC414 “Introduction to UNIX/ Linux” Lecture 3
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 ( >, >>,
Processes Todd Kelley CST8207 – Todd Kelley1.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Pipes and Fifos.
System Administration Performance Monitoring For a server, it is crucial to monitor the health of the machine You need not only real time data collection.
Chapter 11 Command-Line Master Class
Linux 202 Training Module Program and Process.
CSC 382: Computer Security
Operating Systems Lecture 11.
CHAPTER 8 ( , ) John Carelli, Instructor Kutztown University
Operating Systems Lecture 12.
CHAPTER 13 Processes.
CSC 140: Introduction to IT
IPC Prof. Ikjun Yeom TA – Hoyoun
Lab 6: Process Management
Lecture 6 Introduction to Process Management
Presentation transcript:

Operating Systems Yasir Kiani

20-Sep Agenda for Today Review of previous lecture Use of FIFOs in a program Example code Process management commands in UNIX/Linux Recap of lecture

20-Sep Review of Lecture 10 Input, output, and error redirection Use of FIFOs at the command line UNIX/Linux commands: cat, find, grep, mkfifo, tee, wc

20-Sep mknod System Call #include int mknod (const char *path, mode_t mode, dev_t dev);  ‘ mode ’ should be permission mode OR-ed with S_IFIFO  ‘ dev ’ is set to 0 for a FIFO

20-Sep mknod System Call  mknod fails:  File with the given name exists  Pathname too long  A component in the pathname not searchable, non-existent, or non- directory  Destination directory is read-only  Not enough memory space available  Signal caught during mknod

20-Sep mkfifo Library Call #include int mkfifo(const char *path, mode_t mode);  ‘ mode ’ sets permission on FIFO  Calls mknod

20-Sep mkfifo Library Call  mkfifo fails:  File with the given name exists  Pathname too long  A component in the pathname not searchable, non-existent, or non- directory  Destination directory is read-only  Not enough memory space available  Signal caught during mkfifo

20-Sep Example FIFO1 ServerClient Display Screen FIFO2

20-Sep #include extern int errno; #define FIFO1 "/tmp/fifo.1" #define FIFO2 "/tmp/fifo.2" #define PERMS 0666 #define MESSAGE1 "Hello, world!\n" #define MESSAGE2 "Hello, class!\n" Client-Server Code

20-Sep #include "fifo.h“ main() { char buff[BUFSIZ]; int readfd, writefd; int n, size; if ((mknod (FIFO1, S_IFIFO | PERMS, 0) < 0) && (errno != EEXIST)) { perror ("mknod FIFO1"); exit (1); } Server Code

20-Sep if (mkfifo(FIFO2, PERMS) < 0) { unlink (FIFO1); perror("mknod FIFO2"); exit (1); } if ((readfd = open(FIFO1, 0)) < 0) { perror ("open FIFO1"); exit (1); } if ((writefd = open(FIFO2, 1)) < 0) { perror ("open FIFO2"); exit (1); } Server Code

20-Sep size = strlen(MESSAGE1) + 1; if ((n = read(readfd, buff, size)) < 0) { perror ("server read"); exit (1); } if (write (1, buff, n) < n) { perror("server write1"); exit (1); } size = strlen(MESSAGE2) + 1; if (write (writefd, MESSAGE2, size) != size) { perror ("server write2"); exit (1); } close (readfd); close (writefd); } Server Code

20-Sep #include "fifo.h" main() { char buff[BUFSIZ]; int readfd, writefd, n, size; if ((writefd = open(FIFO1, 1)) < 0) { perror ("client open FIFO1"); exit (1); } if ((readfd = open(FIFO2, 0)) < 0) { perror ("client open FIFO2"); exit (1); } Client Code

20-Sep size = strlen(MESSAGE1) + 1; if (write(writefd, MESSAGE1, size) != size) { perror ("client write1"); exit (1); } if ((n = read(readfd, buff, size)) < 0) { perror ("client read"); exit (1); } else if (write(1, buff, n) != n) { perror ("client write2"); exit (1); } close(readfd); close(writefd); Client Code

20-Sep /* Remove FIFOs now that we are done using them */ if (unlink (FIFO1) < 0) { perror("client unlink FIFO1"); exit (1); } if (unlink (FIFO2) < 0) { perror("client unlink FIFO2"); exit (1); } exit (0); } Client Code

20-Sep Running the Code $ gcc server.c –o server $ gcc client.c –o client $ server & [1] $ client Hello, world! Hello, class! $

20-Sep Managing Unix/Linux Processes  Commonly used process management commands: ps – Display status of processes top – Display CPU usage of processes

20-Sep Managing Unix/Linux Processes bg – Put a process in the background fg – Bring a process into the foreground jobs – Display status of jobs

20-Sep Managing Unix/Linux Processes – Suspend/stop a process – Send SIGINT signal to the foreground process kill – Terminate a process

20-Sep The ps command  ps command prints information about active processes.  Without options, ps prints information about processes owned by the user  Commonly used option: -u, -e, and -l

20-Sep $ ps PID TTY TIME CMD 1321 pts/0 00:00:00 csh 1345 pts/0 00:00:00 bash 1346 pts/0 00:00:00 ps $ The ps Command

20-Sep The ps Command $ ps -u root | more PID TTY TIME CMD 1 ? 00:00:04 init 5 ? 00:00:01 kswapd 712 ? 00:00:00 inetd 799 ? 00:00:00 cron 864 ? 00:00:00 sshd 934 ? 00:00:00 httpd 1029 tty1 00:00:00 getty... $

20-Sep The ps Command $ ps -e | more PID TTY TIME CMD 1 ? 00:00:04 init 2 ? 00:00:00 keventd 3 ? 00:00:00 ksoftirqd_CPU0 4 ? 00:00:00 ksoftirqd_CPU1 5 ? 00:00:01 kswapd 6 ? 00:00:00 kreclaimd 7 ? 00:00:00 bdflush 8 ? 00:00:00 kupdated... $

20-Sep The top Command  Displays information about the top processes (as many as can fit on the terminal or around 20 by default) on the system and periodically updates this information.  Raw cpu percentage is used to rank the processes.

20-Sep The top Command $ top 9:42am up 5:15, 2 users, load average: 0.00, 0.00, processes: 54 sleeping, 1 running, 0 zombie, 0 stopped CPU0 states: 0.0% user, 0.1% system, 0.0% nice, 99.4% idle CPU1 states: 0.0% user, 0.2% system, 0.0% nice, 99.3% idle Mem: K av, K used, K free, 60K shrd, 17944K buff Swap: K av, 0K used, K free K cached PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 1406 sarwar R :00 top 1382 nobody S :00 in.telnetd 1 root S :04 init 2 root SW :00 keventd... $

20-Sep Recap of Lecture Use of FIFOs in a program Example code Process management commands in UNIX/Linux ( ps, top ) Recap of lecture