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

Slides:



Advertisements
Similar presentations
Recitation 8 (Nov. 1) Outline Process & job control Lab 5 Reminder Lab 5: Due Thursday Minglong Shao Office hours: Thursdays 5-6PM.
Advertisements

Recitation 8: 10/28/02 Outline Processes Signals –Racing Hazard –Reaping Children Annie Luo Office Hours: Thursday 6:00.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Zombie and orphan processes. Zombie process (from wikipedia) When a process ends, all of the memory and resources associated with it are deallocated.
1 Created by Another Process Reason: modeling concurrent sub-tasks Fetch large amount data from network and process them Two sub-tasks: fetching  processing.
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Operating Systems, Spring 2002 Ittai Abraham, Zinovi Rabinovich (recitation)
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
CS-502 Fall 2006Project 1, Fork1 Programming Project 1 – Fork.
Project 1CS-3013 A-term Programming Project #1 Forking Processes Due Tuesday, September 8, 11:59 PM.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Carnegie Mellon 1 Processes, Signals, I/O, Shell Lab : Introduction to Computer Systems Recitation 9: 10/21/2013 Tommy Klein Section B.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Introduction to Processes CS Intoduction to Operating Systems.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree.
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
The process concept (section 3.1, 3.3 and demos)  Process: An entity capable of requesting and using computer resources (memory, CPU cycles, files, etc).
Operating Systems Chapter 2
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
CS 590 Programming Environments with UNIX. Computer Lab Account Course Homepage
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
More on UART Interrupts; System Calls Reference on Interrupt Identification Register(IIR) slide 17 of
Hands On UNIX II Dorcas Muthoni. Processes A running instance of a program is called a "process" Identified by a numeric process id (pid)‏  unique while.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Scis.regis.edu ● CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University 1.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
System calls for Process management
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
UNIX Socket Programming CS 6378 Project Reference Book: Unix Network programming: Networking APIs: Sockets and XTI (2nd edition), Prentice Hall >> Threads.
Operating Systems Process Creation
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
Outline for Today Objectives –Finish discussion of Birrell –UNIX Signals –Eraser Administrative –Spider talk after class.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Unix System Calls and Posix Threads.
Today’s topic Environment variables Signal. The list of environment variables –try ‘env’ –Environment variables can be defined in shell setenv DISPLAY.
Process Management Azzam Mourad COEN 346.
Concurrent Servers. Idea Behind Concurrent Servers Server Client 1 Server 1 X.
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
System calls for Process management Process creation, termination, waiting.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
The Shell What does a shell do? - execute commands, programs - but how? For built in commands run some code to do the command For other commands find program.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
...looking a bit closer under the hood
Introduction to Kernel
G.Jyostna.
...looking a bit closer under the hood
Hands On UNIX AfNOG 2010 Kigali, Rwanda
Unix Process Management
Threads CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Hands On UNIX AfNOG X Cairo, Egypt
UNIX PROCESSES.
Threads and Cooperation
...looking a bit closer under the hood
Operating Systems Lecture 6.
Programming Project #1 Command Shell
Tutorial: The Programming Interface
Programming Project #1 Fork and Command Shell
CS510 Operating System Foundations
Process Description and Control in Unix
Process Description and Control in Unix
Presentation transcript:

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

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.

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)

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.

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

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

Process Information (Example)

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 /blob/master/pgrep.c

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 ….

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

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?

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

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)

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)

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

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

Submit Use turnin to submit

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

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

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

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