0% found this document useful (0 votes)
34 views14 pages

Operation System Lab 2: by Jin

This document discusses adding a system call to print the currently executing process ID and name during context switches in Linux. It describes modifying the system call table, coding the new system call, adding a header file for user programs, and where the flag would be set in the scheduler. It also defines what a process control block is and provides instructions for demonstrating the new system call.

Uploaded by

shanky094
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views14 pages

Operation System Lab 2: by Jin

This document discusses adding a system call to print the currently executing process ID and name during context switches in Linux. It describes modifying the system call table, coding the new system call, adding a header file for user programs, and where the flag would be set in the scheduler. It also defines what a process control block is and provides instructions for demonstrating the new system call.

Uploaded by

shanky094
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 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 : [email protected]
• 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

You might also like