23-May-15Advanced Programming Spring 2002 Programming approaches Henning Schulzrinne Dept. of Computer Science Columbia University.

Slides:



Advertisements
Similar presentations
Categories of I/O Devices
Advertisements

1 Exceptions, Interrupts & Traps Operating System Hebrew University Spring 2007.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
Signals Hua LiSystems ProgrammingCS2690Signals. Topics: Sending Signals -- kill(), raise() Signal Handling -- signal() sig_talk.c -- complete example.
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 5: Distributed Objects.
OS Spring’03 Introduction Operating Systems Spring 2003.
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.
Section A (March 14) Outline Exceptions Process Signals Non-local jumps Reminders Lab4: Due Next Thursday TA: Kun Gao Shamelessly Modified from Minglong.
Systems Architecture, Fourth Edition1 Internet and Distributed Application Services Chapter 13.
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
DCE (distributed computing environment) DCE (distributed computing environment)
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
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,
4061 Session 15 (3/6). Today More about signals A (relevant) aside Quiz review.
* POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm Topics.
 Advanced programming for the unix environment (chapters 7,8,9 of both editions + chapter 13(2 nd edition))
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Exception Handling Programmers must deal with errors and exceptional situations: User input errors Device errors Empty disk space, no memory Component.
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
IPC Programming. Process Model Processes can be organized into a parent-child hierarchy. Consider the following example code: /* */
COP4020 Programming Languages Exception Handling Prof. Robert van Engelen (modified by Prof. Em. Chris Lacher)
UNIX Socket Programming CS 6378 Project Reference Book: Unix Network programming: Networking APIs: Sockets and XTI (2nd edition), Prentice Hall >> Threads.
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 (Chap 10 in the book “Advanced Programming in the UNIX Environment”) Acknowledgement : Prof. Y. Moon at Kangwon Nat’l Univ.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
UNIX Signals. A UNIX signal corresponds to an event –It is raised by one process (or hardware) to call another process’s attention to an event –It can.
Operating Systems Recitation 4, April th, 2002 Signals.
Signals. Introduction r A signal is a mechanism for notifying a process that an event has occurred. m When a signal is sent to a process is normal execution.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
CSC Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 22, class 5.
© 숙대 창병모 1 제 10 장 신호 (Signal). © 숙대 창병모 2 Contents 1. Signal Concepts 2. signal() 3. Interrupted System Calls 4. kill() /raise() 5. alarm() pause() 6.
University of Washington Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013.
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)
CSCI 330 UNIX and Network Programming Unit XVII: Socket Programming Detail.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Exceptions Exception handling.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
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, Abdelzaher, Caccamo1 Signals.
Setjmp, Longjmp Useful functions for dealing with errors and interrupts setjmp saves its environment (i.e. registers) in env for later use by longjmp After.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
Exceptional Control Flow
Recitation 7 – 3/18/02 Outline fork and scheduling Signals
Recitation 7 (Oct. 25) Outline Minglong Shao Office hours: Reminders
WWW and HTTP King Fahd University of Petroleum & Minerals
Task Control: Signals and Alarms Chapter 7 and 8
Exceptional Control Flow
Threads and Cooperation
Chapter 4: Threads.
CSC Advanced Unix Programming, Fall 2015
Inter-Process Communication
CSE 451: Operating Systems Autumn 2003 Lecture 16 RPC
Operating Systems Chapter 5: Input/Output Management
COP4020 Programming Languages
Signals Tanzir Ahmed CSCE 313 Fall 2018.
Signals.
CSE 451: Operating Systems Winter 2003 Lecture 16 RPC
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

23-May-15Advanced Programming Spring 2002 Programming approaches Henning Schulzrinne Dept. of Computer Science Columbia University

23-May-15Advanced Programming Spring Programming approaches  data-driven  Unix filter model  event-driven  multiple inputs  web models  cgi  multi-layer model  RPC-based models

23-May-15Advanced Programming Spring Data-driven programming  transformational  input stream  f(input, commandline)  output stream  errors go to stderr  status: return code  e.g. pipe,  sort –f out.dat  Advantages:  small, modular tools  easy to script

23-May-15Advanced Programming Spring Data-driven programming  Problems:  line-oriented output  doesn’t work well for networks  sort ?  only for shell, not a GUI abstraction  unconditional, not tree

23-May-15Advanced Programming Spring Event-driven programming  reactive systems: inputs not all available in advanced, but instead arrive in endless and perhaps unexpected sequences  Examples of events:  keystrokes and mouse movements  network requests (e.g., web)  exceptions (connection failed)  file input  directory or file has changed  resource ready (e.g., slow output device)

23-May-15Advanced Programming Spring Event-driven programming  Asynchronous vs. synchronous:  synchronous: wait until operation completes  asynchronous: program is notified when operation completes

23-May-15Advanced Programming Spring Events in Unix  Two event models:  signals – one bit  select/poll – wait for file system or network events  Related: condition variables (later)  Some OS are message-based  Handler or event loop

23-May-15Advanced Programming Spring signals  Software interrupts for asynchronous events  Similar to hardware interrupts  Provide no information beyond name (integer) – SIGxxx  Causes:  control keys on terminal  hardware exceptions:  divide by 0  invalid memory reference (SIGSEGV),  unaligned access (SIGBUS)  kill() or kill command  software conditions (SIGURG, SIGPIPE, SIGALRM, SIGCHLD)

23-May-15Advanced Programming Spring Signal handling  Signals can be ignored (most of them) or caught  Default actions:  ignore  catch  abort  abort with core dump

23-May-15Advanced Programming Spring signal() void (*signal(int signo, void(*func)(int)))(int);  sets signal handler for signo to func  returns previous disposition  function:  SIG_IGN  SIG_DFL  handler returns to calling location, exit() or longjmp()

23-May-15Advanced Programming Spring signal() while (!done) { do something } void handler(int sig) { done = 1; }  only call re-entrant functions: “A reentrant function does not hold static data over successive calls, nor does it return a pointer to static data. All data is provided by the caller of the function. A reentrant function must not call non-reentrant functions.”

23-May-15Advanced Programming Spring Non-re-entrant function char *strtoupper(char *string) { static char buffer[MAX_STRING_SIZE]; int index; for (index = 0; string[index]; index++) buffer[index] = toupper(string[index]); buffer[index] = 0; return buffer; } (from AIX manual)

23-May-15Advanced Programming Spring Re-entrant function (poor) char *strtoupper(char *string) { char *buffer; int index; /* error-checking needed! */ buffer = malloc(MAX_STRING_SIZE); for (index = 0; string[index]; index++) buffer[index] = toupper(string[index]); buffer[index] = 0; return buffer; }

23-May-15Advanced Programming Spring Re-entrant version char *strtoupper_r(char *in_str, char *out_str) { int index; for (index = 0; in_str[index]; index++) out_str[index] = toupper(in_str[index]); out_str[index] = 0; return out_str; }

23-May-15Advanced Programming Spring Non-local jumps  break, continue, return  goto: within same routine  across routines: setjmp, longjmp int setjmp(jmp_buf env); void longjmp(jmp_buf env, int val);

23-May-15Advanced Programming Spring Signal example if (signal(SIGUSR1, sigusr1) == SIG_ERR) { perror("signal"); } if (setjmp(jmpbuffer) != 0) { printf("we are done!\n"); exit(1); } while (1) { printf("looping...\n"); } void sigusr1(int sig) { longjmp(jmpbuffer, 1); }

23-May-15Advanced Programming Spring longjmp  Careful: return from the wild  setjmp() saves stack frame, sigsetjmp() saves registers, too  declare variables as volatile!  can also save signal mask, priority

23-May-15Advanced Programming Spring Example: alarm() unsigned int alarm(unsigned int s);  generates SIGALRM after s seconds  returns time to next alarm  only one pending alarm  s=0 cancels alarm  pause() waits until signal

23-May-15Advanced Programming Spring Web programming models  Web is stateless – send request, get response based on request  By default, no global variables or persistent objects  Like a function call (also with side effects):   similar to People::Show(Name,17);

23-May-15Advanced Programming Spring Web programming  No state – add client or server state  client: cookies encapsulate data  server: keep track in database (rare)  State leakage – client may never come back  Scripts typically deliver HTML, but can provide any data (say, video clip)  typically, unstructured user-oriented data  RPC

23-May-15Advanced Programming Spring Limitations of web model  We’ll experiment a bit later, but...  Error handling in band  Conditional programming: many argument combinations  user interaction requires new request submission  user data checking (JavaScript)  synchronous – can’t notify user if something changes

23-May-15Advanced Programming Spring Remote procedure calls (RPC)  Mimic function calls: arguments, return values, side effects,...  But across network -> client/server computing  Many, many implementations:  Sun RPC  Distributed Computing Environment (DCE), by DEC and OSF  Corba  Java RemoteMethodInvocation  SOAP (HTTP-based)

23-May-15Advanced Programming Spring Common functionality  Find appropriate server  by name  by services offered (“service brokering”)  Authenticate to server  Encapsulate requests  Send across network  Wait for completion or asynchronous  Get result and convert to local representation