CSC 552.201 - Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 22, class 5.

Slides:



Advertisements
Similar presentations
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Advertisements

Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
2.3 InterProcess Communication (IPC) Part A. IPC methods 1. Signals 2. Mutex (MUTual EXclusion) 3. Semaphores 4. Shared memory 5. Memory mapped files.
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
1 Select and poll and Signals CS 241 April 6, 2012 University of Illinois.
23-May-15Advanced Programming Spring 2002 Programming approaches Henning Schulzrinne Dept. of Computer Science Columbia University.
CPSC 451 Editors and Systems Calls1 Minix editors Mined - (mined) is a simple screen editor. Elle - (elle) is a clone of Emacs. Elvis - (elvis, ex, vi)
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
CS Lecture 17 Outline Named pipes Signals Lecture 17
Signals Hua LiSystems ProgrammingCS2690Signals. Topics: Sending Signals -- kill(), raise() Signal Handling -- signal() sig_talk.c -- complete example.
Operating Systems Course Hebrew University Spring 2007 Signals & User Thread.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
1 Signals COS Goals of Today’s Lecture Overview of signals  Notifications sent to a process  UNIX signal names and numbers  Ways to generate.
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
Signal Signal : - is a notification sent to a process to notify it of some event - interrupts whatever the process is doing and force it to handle a signal.
B. RAMAMURTHY Pag e 1 Task Control: Signals and Alarms Chapter 7 and 8 7/2/2015.
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
COMP5102 Lecture 4 Operating Systems (OS) Inter-process Communication phones off (please)
Process states inWindows 2000 and Linux Module 2.1.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Signals & Timers CS241 Discussion Section Spring 2009 Week 6.
Operating Systems Yasir Kiani. 22-Sep Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread.
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
CSC Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 15, class 4.
Operating Systems Chapter 2
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
The kernel considers each program running on your system to be a process A process lives as it executes, with a lifetime that may be short or long A process.
Operating Systems CSE 411 CPU Management Sept Lecture 9 Instructor: Bhuvan Urgaonkar.
1GWU CS 259 Brad Taylor Spring 2004 Systems Programming Meeting 5: Signals, Time, Timers, and Token Rings.
* POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm Topics.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R S I X Exception Handling.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
UNIX Socket Programming CS 6378 Project Reference Book: Unix Network programming: Networking APIs: Sockets and XTI (2nd edition), Prentice Hall >> Threads.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Signals and Signal Processing CIS 370 Lab 7 Umass Dartmouth.
Outline for Today Objectives –Finish discussion of Birrell –UNIX Signals –Eraser Administrative –Spider talk after class.
Signals and Signal Handling. Signals A predefined message sent between two processes or from the kernel to a process, or by a user to a process A software.
Signals (Chap 10 in the book “Advanced Programming in the UNIX Environment”) Acknowledgement : Prof. Y. Moon at Kangwon Nat’l Univ.
NCHU System & Network Lab Lab #8 Signals Operating System Lab.
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 *
Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.
Operating Systems Recitation 4, April th, 2002 Signals.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Unix System Calls and Posix Threads.
KUKUM Real Time System Module #3 POSIX programming Lecture 2.
© 숙대 창병모 1 제 10 장 신호 (Signal). © 숙대 창병모 2 Contents 1. Signal Concepts 2. signal() 3. Interrupted System Calls 4. kill() /raise() 5. alarm() pause() 6.
Today’s topic Environment variables Signal. The list of environment variables –try ‘env’ –Environment variables can be defined in shell setenv DISPLAY.
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
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)
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Signals.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.
Operating Systems Inter-Process Communication Signals Moti Geva
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
UNIX signals.
Task Control: Signals and Alarms Chapter 7 and 8
UNIT-IV Process and Signals
CSC Advanced Unix Programming, Fall 2015
Operating Systems Lecture 12.
Signals Tanzir Ahmed CSCE 313 Fall 2018.
Inter-Process Communication ENCE 360
Task Control: Signals and Alarms Chapter 7 and 8
CSE 451: Operating Systems Spring 2006 Module 4 Processes
Signals.
Presentation transcript:

CSC Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 22, class 5

sigaction() and signal() and kill() A UNIX signal is like a user-process-level interrupt. Each distinct signal provides a way to trigger asynchronous processing in a single- threaded (or multi-threaded) process. sigaction() system call specifies a handler signal() was the old way of doing that kill() system call sends a signal to another process

sigaction() #include int sigaction(int sig, const struct sigaction *restrict act, struct sigaction *restrict oact); The sigaction() function allows the calling process to examine or specify the action to be taken on delivery of a specific signal. See signal.h(3HEAD) for an explanation of general signal concepts. The sigaction structure includes the following members: void (*sa_handler)(int); // SIG_DFL, SIG_IGN or event-handling function void (*sa_sigaction)(int, siginfo_t *, void *); // realtime handler sigset_t sa_mask; // other signals to be blocked during execution int sa_flags; //flags and options

signal.h Signals / default actions are on p. 257 of text SIGHUP 1 Exit Hangup (see termio(7I))SIGINT 2 Exit Interrupt (see termio(7I)) SIGQUIT 3 Core Quit (see termio(7I)) SIGILL 4 Core Illegal Instruction SIGTRAP 5 Core Trace or Breakpoint Trap SIGABRT 6 Core Abort SIGEMT 7 Core Emulation TrapSIGFPE 8 Core Arithmetic Exception SIGKILL 9 Exit Killed SIGBUS 10 Core Bus Error SIGSEGV 11 Core Segmentation FaultSIGSYS 12 Core Bad System Call SIGPIPE 13 Exit Broken PipeSIGALRM 14 Exit Alarm Clock SIGTERM 15 Exit Terminated SIGUSR1 16 Exit User Signal 1 SIGUSR2 17 Exit User Signal 2 SIGCHLD 18 Ignore Child Status Changed SIGPWR 19 Ignore Power Fail or RestartSIGWINCH 20 Ignore Window Size Change SIGURG 21 Ignore Urgent Socket ConditionSIGPOLL 22 Exit Pollable Event (see streamio(7I)) SIGSTOP 23 Stop Stopped (signal)SIGTSTP 24 Stop Stopped (user) (see termio(7I)) SIGCONT 25 Ignore ContinuedSIGTTIN 26 Stop Stopped (tty input) (see termio(7I)) SIGTTOU 27 Stop Stopped (tty output) (see termio(7I))SIGVTALRM 28 Exit Virtual Timer Expired SIGPROF 29 Exit Profiling Timer ExpiredSIGXCPU 30 Core CPU time limit exceeded (see getrlimit(2)) SIGXFSZ 31 Core File size limit exceeded (see getrlimit(2)) Some abort the process, some core dump by default.

kill() kill() send a signal to a process #include int kill(pid_t pid, int sig); pid from getpid(), getppid(), fork() You could pass them via pipes or FIFOs. kill also available as level 1 shell /usr/bin/kill unsigned alarm(unsigned secs) schedules SIGALRM

signal masks signal masks disable target signals until a masked signal is re-enabled unlike SIG_IGN, the ignore+discard handler sigset_t objects can be set up for signals, similar to setting up fd_sets for select()/poll() int sigprocmask(…) sets up signal masks at the process level pthread_sigmask for multi-threaded processes

pause() int pause(void) pauses until interruption by a signal always returns -1 pause() suffers from a race condition – between a call to sigprocmask() and pause(), the signal may already have arrived and been handled signal unmasking and pausing should be atomic

sigsuspend and sigwait int sigsuspend(const sigset_t *set); set is set of masked (disabled) signals former set is restored on return after a non-terminating signal int sigwait(const sigset_t *set, int *sig); synchronously wait on a set of signals in the set this set is independent of the process mask (and thread masks) disable those signals in the process (and thread) masks via sigprocmask() in order to avoid “competition”

race conditions Most 3C library functions and many system calls are not safe to use in a signal handler because its asynchronous execution may occur within a critical section! Text p. 285 holds a list of safe POSIX functions. Perform minimal flag setting within signal handlers. Do not block indefinitely! Do not use sigsetjmp, siglongjmp, setjmp, longjmp – they leak storage from the stack!

Asynchronous I/O and signals aio_read() and aio_write() use signals to generate events on I/O completion. Doing substantial data processing inside a signal handler is extremely error prone! Create a worker thread that is allowed to block, and let it blocks using select(), read() and write(). It can use semaphores, etc. to sync with other threads. Signal handlers cannot!

Assignment: Spy on GNU chess! Your initial assignment is to write an interceptor that sits between xboard and gnuchess and logs interactions while you play chess. Use your trace log plus source code and docs to understand the xboard gnuchess command and results protocol. xboard interceptor gnuchess xboard » stdin log, stdout log, stderr log for gnuchess

The bigger assignment: Sound Install ChucK on a machine with some speakers. My chess program, linked to my web page, as a ChucK directory, with a README. Open Sound Control (OSC) over UDP datagrams  a ChucK process running my sound generator  speakers But, Professor Parson, where do the OSC/UDP datagrams comes from?

A Python chess-to-music game One or more Python game GUIs  Python game server that takes commands from command line (stdin / stdout), and also accepts GUI commands from UDP datagrams. This Python program generates OSC/UDP  ChucK. The command line server, like gnuchess, is a stdin / stdout / stderr process.

Project goals Allow Python chess-to-music program to play a human against the machine (gnuchess). Support alternative, networked GUI (in Python) for gnuchess. Have some fun while learning fork, exec, file IO, sockets, networking and multithreading. Live long and prosper.

Summary Ultimately you are creating a game framework to integrate two or more running games. An ideal goal would be to allow support for different protocols using a plugin parser. The immediate goal is to intercept, redirect, etc. commands passing between xboard gnuchess, and also my Python game server Python GUI, and to translate between them.