Operating Systems Recitation 5, April 21-22, 2002 slide 13 updated April 28 th.

Slides:



Advertisements
Similar presentations
Essential System Administration 3rd Edition Chapter 2 The Unix Way(Cont.) University Of Palestine.
Advertisements

1 Introduction to UNIX Ke Liu
Shells and Processes Bryce Boe 2012/08/08 CS32, Summer 2012 B.
CS 497C – Introduction to UNIX Lecture 26: - The Process Chin-Chih Chang
1 Case Study 1: UNIX and LINUX Chapter History of unix 10.2 Overview of unix 10.3 Processes in unix 10.4 Memory management in unix 10.5 Input/output.
Linux+ Guide to Linux Certification, Second Edition
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.
Operating Systems Recitation 11, June 9-10, 2002.
More Shell Programming Learning Objectives: 1. To learn the usage of environment (shell) variables in shell programming 2. To understand the handling of.
Processes & Daemons Chapter IV / Part III. Commands Internal commands: alias, cd, echo, pwd, time External commands, code is in a file: grep, ls, more.
Introduction to Linux/UNIX. History UNIX beginnings in 1969 (Linus Torvalds is born!) AT & T Bell Laboratories (Ken Thompson & Dennis Richie) Working.
Linux Commands LINUX COMMANDS.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
File Permissions. What are the three categories of users that apply to file permissions? Owner (or user) Group All others (public, world, others)
Linux+ Guide to Linux Certification, Second Edition
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree.
Operating Systems Recitation 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Operating Systems Recitation 1, March th, 2002.
Lecture 4  C Shell Scripts(Chapter 10). Shell script/program  Shell script: a series of shell commands placed in an ASCII text file  Commands include.
LINUX System : Lecture 6 Shell Programming
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
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.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
L&T Infotech1 UNIX – Getting Started - Aneesh Ramani.
Scis.regis.edu ● CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University 1.
Linux+ Guide to Linux Certification, Third Edition
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
Lab 3 + Using the Terminal 1. "Under Linux there are GUIs (graphical user interfaces). where you can point and click and drag, and hopefully get work.
CSI3131 – Lab 1 Observing Process Behaviour. Running Linux under Virtual PC  Start Virtual PC  This Windows program provides a virtual machine to run.
Operating Systems Recitation 4, April th, 2002 Signals.
Getting Started UNIX InKwan Yu Topics Unix Commands Unix System calls C function calls.
Advanced Programming in the UNIX Environment Hop Lee.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
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.
Module 1 - Introduction to Linux. Users must log-in Linux is case sensitive File and Directories naming conventions (No spaces!) Files and Directories.
Linux A practical introduction. 1)Background and Getting Started Linux is an operating system with multiple providers Red Hat/CentOS (our version) Ubuntu.
Linux Processes Last Update Copyright Kenneth M. Chipps Ph.D. 1.
A Mini UNIX Tutorial. What’s UNIX?  An operating system run on many servers/workstations  Invented by AT&T Bell Labs in late 60’s  There are many different.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Getting Started with Linux
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Getting started with CentOS Linux
Case Study 1: UNIX and LINUX
Proc File System Sadi Evren SEKER.
Some Linux Commands.
C151 Multi-User Operating Systems
Shell Script Assignment 1.
Introduction to UNIX.
Using the Terminal Lab 3+.
Structure of Processes
(Chapter 2) John Carelli, Instructor Kutztown University
Unix : Introduction and Commands
Introduction to Linux/UNIX
Shells, Help, and Paths.
Getting started with CentOS Linux
CSE 303 Concepts and Tools for Software Development
Linux Commands LINUX COMMANDS.
Chapter 2: OS Structures CSS503 Systems Programming
January 26th, 2004 Class Meeting 2
Presentation transcript:

Operating Systems Recitation 5, April 21-22, 2002 slide 13 updated April 28 th

Shell Interactive use Session customization Programming Linux kernelLinux shell programUser

Command interpretation by the shell user commands Shell commands cd, pwd, kill, exit, etc. Unix system calls fork, iocntl, read, exec, open, write, etc. Unix utility programs ls, rm, cp, etc. Other applications emacs, xv, etc. External commands Shell Unix kernel

csh (C shell) - example 1 A series of individual commands (shell or other Linux commands) combined into one executable file is called a shell script, similar to a batch file in MS-DOS. Many of the programming constructs resemble those of C. #!/bin/csh foreach f (*) echo $f end ls -l ex-ps]# csh ex-ls

csh - example 2 #!/bin/csh set argc = $#argv if ($argc < 2) then echo "usage: ex-mv " exit(1) endif set extension = $argv[1] set filenames = ($argv[2-$argc]) foreach name ($filenames) set prefix = $name:r set newname = $prefix.$extension mv $name $newname end ex-ps]# csh ex-mv cpp 1.c 2.c

#!/bin/csh set argc = $#argv if ($argc < 2) then echo "usage: ex-large " exit(1) endif set size = $argv[1] set filenames = ($argv[2-$argc]) … csh - example 3 set column = 5 set sum = 0 foreach file ($filenames) set line = `ls -l $file` set filesize = $line[$column] if ($filesize > $size) then echo $file sum = $sum + $filesize n = $argc - 1 if ($n != 0 && $sum != 0) average = $sum / $n echo "average size is $average" endif

Virtual file system Kernel software layer that handles system calls related to a standard Unix file-system. Common model representing all supported file systems: disk-based, network, and special file-systems that do not manage disk space at all, such as the process file- system.

Example Virtual file system MS-DOSExt2 cp /tmp/test /floppy/TEST ]# cp /floppy/TEST /tmp/test

Process file system (/proc) Interface, no persistent data. Each subdirectory corresponds to an active process, directory name is PID. Additional directories provide global statistics about the kernel and drivers. Access via plain text, computed on demand.

os]# emacs HelloWorld.java & [1] 2912 os]# cd / /]# cd proc /proc]# ls cmdline interrupts meminfo slabinfo cpuinfo … 2912 … /proc]# cd ]# ls -l total 0 -r--r--r-- 1 root root 0 Apr 20 01:18 cmdline lrwxrwxrwx 1 root root 0 Apr 20 01:18 cwd -> /home/idrori/os -r root root 0 Apr 20 01:18 environ lrwxrwxrwx 1 root root 0 Apr 20 01:18 exe -> /usr/bin/emacs dr-x root root 0 Apr 20 01:18 fd -r--r--r-- 1 root root 0 Apr 20 01:18 maps -rw root root 0 Apr 20 01:18 mem lrwxrwxrwx 1 root root 0 Apr 20 01:18 root -> / -r--r--r-- 1 root root 0 Apr 20 01:18 stat -r--r--r-- 1 root root 0 Apr 20 01:18 statm -r--r--r-- 1 root root 0 Apr 20 01:18 status Example

2912]# more cmdline emacsHelloWorld.java 2912]# more status Name: emacs State: S (sleeping) Pid: 2912 PPid: 2189 TracerPid: 0 Uid: Gid: FDSize: 32 Groups: VmSize: 9000 kB … VmData: 896 kB VmStk: 672 kB VmExe: 992 kB VmLib: 3576 kB SigPnd: SigBlk: SigIgn: ]#

Exercise description Write a csh program (ex-ps) that specifies the running processes in the system, their user name and running command. The program should print a line for each process.

Exercise - notes informationlocationComment pid/proc/*check for numbered directory names by calling the executable of isnum.c uid/proc/pid/statusgrep Uid field cmdline/proc/pid/cmdline username/etc/passwd ypmatch $uid passwd.byuid | gawk 'BEGIN {FS=":|,";} {print $5;}‘ Write a small C program, isnum.c (whose executable is isnum), that checks if its argument is numeric, and use it to check for directories in proc that correspond to processes. The following table provides the location of necessary information: you can use the –x flag to echo each line of your script (for debugging purposes only) #!/bin/csh -x

Notes When you log in, the system determines which shell to run by your entry in /etc/passwd The default shell on Linux is bash. You can change the shell using the command chsh –s /bin/csh, or by typing the program name at the command line, exec csh

Chapter 4.10, pages 77-78, in Toledo’s book. Submission: Monday, May 6 th. Software Directory: ~username/os02b/ex-ps Files: ex-ps, isnum.c Permissions: chmod ugo+rx (to above) Hardcopy name, ID, login, CID ex-ps, isnum.c submit in mailbox 281, Nir Neumark,