Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Operating Systems Recitation 5, April 21-22, 2002 slide 13 updated April 28 th."— Presentation transcript:

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

2 Shell Interactive use Session customization Programming Linux kernelLinux shell programUser

3 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

4 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 [root@pc ex-ps]# csh ex-ls

5 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 [root@pc ex-ps]# csh ex-mv cpp 1.c 2.c

6 #!/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 endif @ sum = $sum + $filesize end @ n = $argc - 1 if ($n != 0 && $sum != 0) then @ average = $sum / $n echo "average size is $average" endif

7 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.

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

9 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.

10 [root@pc os]# emacs HelloWorld.java & [1] 2912 [root@pc os]# cd / [root@pc /]# cd proc [root@pc /proc]# ls 1 1292 1408 1972 4 8 cmdline interrupts meminfo slabinfo 1007 1296 1409 1974 5 845 cpuinfo … 2912 … [root@pc /proc]# cd 2912 [root@pc 2912]# 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-------- 1 root root 0 Apr 20 01:18 environ lrwxrwxrwx 1 root root 0 Apr 20 01:18 exe -> /usr/bin/emacs dr-x------ 2 root root 0 Apr 20 01:18 fd -r--r--r-- 1 root root 0 Apr 20 01:18 maps -rw------- 1 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

11 [root@pc 2912]# more cmdline emacsHelloWorld.java [root@pc 2912]# more status Name: emacs State: S (sleeping) Pid: 2912 PPid: 2189 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 32 Groups: 0 1 2 3 4 6 10 VmSize: 9000 kB … VmData: 896 kB VmStk: 672 kB VmExe: 992 kB VmLib: 3576 kB SigPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 8000000000000000... [root@pc 2912]#

12 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.

13 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

14 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

15 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, nirn@post.tau.ac.ilnirn@post.tau.ac.il


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

Similar presentations


Ads by Google