Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE451 Section 2: Spring 2006 Kurtis Heimerl, YongChul Kwon

Similar presentations


Presentation on theme: "CSE451 Section 2: Spring 2006 Kurtis Heimerl, YongChul Kwon"— Presentation transcript:

1 CSE451 Section 2: Spring 2006 Kurtis Heimerl, YongChul Kwon kheimerl@cs, yongchul@cs

2 Office hour Prof. John Zahorjan –Wed 3:30 – 4:20 @ CSE534 YongChul Kwon –Mon & Thr 2:30-3:20 @ CSE216 –By appointment Kurtis Heimerl –Mon & Wed & Fri 12:30-1:20 @ CSE002 –By appointment

3 Reminders Section leader –AA: Kurtis Heimerl –AB: YongChul Kwon Read & start project 1 –Project 1 due Apr 14 11:00am Be familiar with VMware ® Check access to –forkbomb.cs.washington.edu

4 Proj1: Shell & system call Sharpening your C edge! Understand & practice –Library call & system call –Stack of H/W to user Apps –Working at kernel level By –Design & implement simple shell & system call

5 Shell? 9. Computer Science A program that works with the operating system as a command processor, used to enter commands and initiate their execution. -- American Heritage ® Dictionary of the English Language

6 Why do we call it ‘shell’? For Linux? For Windows®? H/W Operating System Shell Firefox Powerpoint

7 Library call & system call Library call –Not using any OS service –Provide a high level interface for OS service System call –Using some OS service –Process/Signal/File/Network/IPC/… What happens when we call –strncpy(3) –fgets(3)

8 Key C functions for shell String –strcmp, strncpy, strtok, atoi I/O –fgets Error report –perror Process control –fork, wait or waitpid, execv or execvp Environment variable –getenv Don’t forget to read manual pages of these!

9 Typical skeleton for shell Bool exit = false; while ( !exit ) { /* read command line from user */ /* parse command line */ if ( it is internal command ) { /* execute internal command */ } else { pid_t pid = fork(); /* spawn a new process */ if ( pid == 0 ) { /* call exec to launch requested program */ } else if ( pid < 0 ) { /* print error message: fork failed */ } else { /* wait until launched program terminates */ } } }

10 Internal Vs. External command Internal command –By executing routines embedded in a shell –Manage states of the shell –Shell scripts Shell has its own states –Current working directory –Alias to a command line –Environment variable –Processes spawned by the shell –…–… Then what does external command do?

11 New system call: execcounts Count # of process invocation calls –fork –vfork –clone –execve executed for a specific process and all of its descendants

12 Writing our system call Write a library for the new system call stub code –Refer the project description Modify your PCB definition(struct task_struct) –include/linux/sched.h(in kernel source) Modify code to maintain values correctly –A specific process and all of its descendants Implement a system call to retrieve this information Modify your library code

13 Tips Read the project instructions thoroughly! Find some useful functions in –include/linux/sched.h –inlcude/asm/current.h Don’t forget to you are working in Kernel mode –Be careful in translating addresses Learn by example –Investigate how other system calls are implemented –Recommended: getpid(), kill(), write()


Download ppt "CSE451 Section 2: Spring 2006 Kurtis Heimerl, YongChul Kwon"

Similar presentations


Ads by Google