Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS252: Systems Programming Ninghui Li Topic 18: Lab 6: The Process Games.

Similar presentations

Presentation on theme: "CS252: Systems Programming Ninghui Li Topic 18: Lab 6: The Process Games."— Presentation transcript:

1 CS252: Systems Programming Ninghui Li Topic 18: Lab 6: The Process Games

2 The Process Games In each process game, between 2 and 5 programs can participate. The arena program creates (i.e., forks) N processes of each program, where N is at least 10, and N*P is at most 100. Each program is loaded with N and P given as arguments. The total number of processes in the arena is limited to N*P once the arena starts.

3 The Players The goal of a participating program is to make as many processes in the arena to be duplicates of itself. A player must thus Find target Use /proc, guess PID, etc. Kill target (kill) Duplicate itself (fork)

4 Finding Other Processes via /proc What is /proc? A pseudo-filesystem that acts as an interface to internal data structures in the kernel What is it used for? Can be used to obtain information about the system Can be used to change certain kernel parameters at runtime.

5 Why the Pseudo-File System Create pseudo-filesystem to represent status information and configuration parameters as files Provides a unified ‘API’ for collecting status information and configuring drivers Control access through UNIX permissions No new libraries needed – simple filesystem calls are all that is necessary Quick, easy access via command line Not version- or configuration-specific

6 Process Information Each process has a /proc directory identified by its PID - /proc/PID/ Symlink /proc/self/ points to the process reading the file system Allows access to Process status Process memory information Links to cwd, exe, root dir Pending signals Many other information

7 Process Information (Example)

8 Accessing /proc Use standard filesystem API Including openat/getdents/opendir/readdir/readlink/read Use /proc specific api I.e., openproc/readproc/readproctab See, e.g., source code of pkill/pgrep at 3.0.5/blob/master/pgrep.c

9 Friend or Foe? Possible strategies Check whether /prof/pid/exe matches argv[0] Use IPC between friends E.g, use shared memory as a bulletin board shared by all friends E.g., use signals Possibly others Don’t care ….

10 How to Coordinate? Global coordination (E.g., shared memory) Local coordination Each process makes decision based on local information No coordination

11 Strategic Thinking Fast and furious versus methodical Is the overhead worthwhile? Should one use different strategies based on values of N, P? Should one have different instances of the players adopt different strategies?

12 Other Things to Explore Understand what existing players do? Use strace to find out the system calls made by a player, and experiment to understand relative performances The result may be surprising, Understand process scheduling and system calls made Possibly use auditctl

13 Grading Base score = Avg score over applicable testing scenarios In each scenario, Avg of middle 3 performances, each measured as the percentage of remaining processes after 10 seconds, 1. vs. fork(N=10, 20, 30, 40, 50) 2. vs. digger(N=10, 20, 30, 40, 50) 3. vs. sniper(N=10, 20, 30, 40, 50) 4. vs. phalanx(N=10, 20, 30, 40, 50) 5. vs. hitman(N=10, 20, 30, 40, 50)

14 Grading (Continued) 6. vs. digger + sniper(N=10, 15, 20, 25, 30) 7. vs. phalanx + sniper(N=10, 15, 20, 25, 30) 8. vs. hitman + phalanx(N=10, 15, 20, 25, 30) Team of 4(all 8 scenarios) Team of 3 (scenarios 1-7) Team of 2 (scenarios 1-6) Team of 1 (scenarios 1-5)

15 Grading: Extra Credit 10% extra for winning against flash (N=10, 20, 30, 40, 50) Top 8 joins a tournament, receiving 10%, 8%, 6%,5%,4%,3%,2%,1% extra credit

16 How to Set UP? Install Oracle Virtual Box Download the VM image Log in as cs252 Commands cd lab6, su arena1 or arena2./arena 20./fork./prog sudo bash top –u arena1 pgrep –lu arena1 progshow remaining processes pkill –KILL –u arena1

17 Submit Use turnin to submit

18 Clicker Question 1 (signals) Which signal is sent when the Child process terminates? A. SIGINIT B. SIGCHLD C. SIGKILL D. SIGSTOP E. None of the above

19 Clicker Question 2 (Signals) Which of the following signal cannot be handled or ignored? A. SIGINT B. SIGCHLD C. SIGKILL D. SIGALRM E. None of the above

20 Clicker Question 3 (Signals) Which system call(s) cause the sending of a signal? A. kill B. signal C. sigaction D. Both A and B E. Both B and C

21 Clicker Question 4 (Signals) What is the output of the code below? void handler ( int signum) { printf(“Handled signal\n”) } int main() { int pid; signal (SIGKILL, handler); pid = fork(); if (pid==0) { kill(getppid(), SIGKILL); exit(0); } else { sleep(20); } return 0; } A.Error child cannot send a SIGKILL signal to parent. B.Parent goes to the signal handler, prints “handled signal” and goes back to sleep C.Parent goes to the signal handler, prints “handled signal” and exits D.Parent sleeps for 20 seconds, without going to signal handler E.Parent exits without going to the signal handler

Download ppt "CS252: Systems Programming Ninghui Li Topic 18: Lab 6: The Process Games."

Similar presentations

Ads by Google