Вы находитесь на странице: 1из 14

Operation System

Lab 2

By Jin

2005/04/07
Goals
• Print the currently executing process
– Use one system call to turn on a flag
– Such that every time when context switching,
scheduler would print the current process ID
and NAME
– Use another system call to turn off the flag,
and then scheduler would stop printing
Print the currently executing process
• main() {

• flag_on(); //system call to turn on the flag

• sleep(10); /*make sure context switching


would be happened*/

• flag_off(); //system call to turn off the flag



• }
WWW
• hoW to add a system call
• What is PCB
• Where is the Flag
How to add a system call
• Modify the table of system calls
• Code your system calls
• Add the *.h for user program
• User program
Modify the table
• vi /usr/src/linux/arch/i386/kernel/entry.S

• ………
• ………
• .long sys_myservice /* 28x */
Code
• ………
• #include <linux/linkage>

• ……
• asmlinkage int sys_myservice(int arg1, char* arg2 ) {
………
return (1);
}
*.h for user program
• #include <linux/unistd.h>
• .........
• #define __NR_myservice 28x
• ………
• ………
• _syscall2(int, myservice, int, arg1, char*, arg2);

User program
• #include <…/*.h>
• ………
• ………
• main() {
• ………
• myservice(1, ”hi”);
• ………
• }
What is the PCB
• Process Control Block
– PID
– Process name
– Status
– File system
– Previous PCB
– Next PCB
– …….
Where is the Flag
• /usr/src/linux/kernel/sched.c

• int flag=0;
• int counter=0;
• Function schedule() {
– ………

– //when context switching


– if (flag==1) {
• printk(“The Current Process ID is %d\n”,PCB->pid);
• printk(“The Current Process NAME is %s\n”,PCB->name);
• counter++;
– }

– ……
• }
DEMO
• Print initial value of the flag
• Turn on the flag
• Show the PID and NAME of the currently
executing process
• Turn off the flag
• Print the finial value of the flag
• Print the count of content switching
Note
• Reserve the old kernel
• Add system calls in new kernel
– make clean
– make bzImage
– Try your new kernel on the computers at LAB 220 bef
ore DEMO
• Running in the console mode

• E-Mail : jcchou@csie.nctu.edu.tw
• TA office hours : Friday GH
References
• How to add a System call

http://fossil.wpi.edu/docs/howto_add_syste
mcall.html
• Process Control Block
“Linux Kernel Development” -- Robert Love

Вам также может понравиться