Академический Документы
Профессиональный Документы
Культура Документы
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
• ………
• ………
• .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() {
– ………
– ……
• }
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