Section 3 Syscalls, I/O, Signals February 3rd, 2017 Taught by Josh Don.

Slides:



Advertisements
Similar presentations
Recitation By yzhuang, sseshadr. Agenda Debugging practices – GDB – Valgrind – Strace Errors and Wrappers – System call return values and wrappers – Uninitialization.
Advertisements

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.
Processes 2: Signals & Pipes CS 360 proc2. Page 2 proc2 CS 360 WSU Vancouver The Big Picture For processes to cooperate, they must share data 4 why aren't.
15-213, Fall 06 Outline Shell Lab Processes Signals.
Operating System Inter-Process Communication. IPC F How does one process communicate with another process? –semaphores -- signal notifies waiting process.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Operating Systems, Spring 2002 Ittai Abraham, Zinovi Rabinovich (recitation)
Unix System Programming Chung-Ta King Department of Computer Science National Tsing Hua University.
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.
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.
Processes, Signals, I/O, Shell lab
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Recitation 11: I/O Problems Andrew Faulring Section A 18 November 2002.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Agenda  Terminal Handling in Unix File Descriptors Opening/Assigning & Closing Sockets Types of Sockets – Internal(Local) vs. Network(Internet) Programming.
1 Shell Programming – Extra Slides. 2 Counting the number of lines in a file #!/bin/sh #countLines1 filename=$1#Should check if arguments are given count=0.
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Recitation 11: 11/18/02 Outline Robust I/O Chapter 11 Practice Problems Annie Luo Office Hours: Thursday 6:00 – 7:00 Wean.
Pipes A pipe is a simple, synchronized way of passing information between processes A pipe is a special file/buffer that stores a limited amount of data.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
Agenda  Redirection: Purpose Redirection Facts How to redirecting stdin, stdout, stderr in a program  Pipes: Using Pipes Named Pipes.
Chapter 71 Deadlock Detection revisited. Chapter 72 Message Passing (see Section 4.5 in Processes Chapter)  A general method used for interprocess communication.
S -1 Pipes. S -2 Inter-Process Communication (IPC) Chapter Data exchange techniques between processes: –message passing: files, pipes, sockets.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Basic I/O in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Stream Model of I/O header file: A stream provides a connection.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
UNIX signals & pipes. UNIX Signals A UNIX signal corresponds to an event –It is raised by one process (or hardware) to call another process’s attention.
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.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Recitation 11 (Nov. 22) Outline Lab 6: interposition test Error handling I/O practice problem Reminders Lab 6: Due Tuesday Minglong Shao
Recitation: Signaling S04, Recitation, Section A Debug Multiple Processes using GDB Debug Multiple Processes using GDB Dup2 Dup2 Signaling Signaling.
Signals & Message queue Inter process mechanism in Linux system 3/24/
CSCI 330 UNIX and Network Programming
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
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.
Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.
Agenda  Protecting Shared Resources (Critical Sections of Programming Code): Problem of Shared read/write files Solution: Files Locks: Read Locks Write.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Overview Dr. Xiao Qin Auburn University
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 4: Managing File System State Dr. Xiao Qin Auburn University.
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.
CSE120 Discussion 5 Xinxin Jin. Where Are We?  Now we have finished some thread mechanisms to support Nachos kernel  Next, we want to enable user-level.
CS/COE 0449 (term 2174) Jarrett Billingsley
Lecture 5 Systems Programming: Unix Processes: Orphans and Zombies
G.Jyostna.
Week 3 Redirection, Pipes, and Background
Operating Systems Moti Geva
Robust I/O package Chapter 11 practice problems
Operating Systems Review ENCE 360.
Precept 14 : Ish dup() & Signal Handling
Exceptional Control Flow
Basic Processor Structure/design
CS1010 Programming Methodology
File redirection ls > out
LINUX System Programming with Processes (additional)
תרגול 8 – ק/פ ותקשורת תהליכים ב-Linux
Inter-Process Communication
Program Requirements.
Andy Wang Operating Systems COP 4610 / CGS 5765
Programming Assignment # 2 – Supplementary Discussion
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
IPC Prof. Ikjun Yeom TA – Hoyoun
Exceptional Control Flow
Inter-Process Communication ENCE 360
CSCI 380: Operating Systems William Killian
Presentation transcript:

Section 3 Syscalls, I/O, Signals February 3rd, 2017 Taught by Josh Don

Signals Signal: An asynchronous notification sent to a process to notify it that an event has occurred When a signal is sent, the OS interrupts the process’ normal flow of execution to deliver the signal Ex: Ctrl-C sends SIGINT

List of Signals

Run default signal handler for SIGINT! Signals Run default signal handler for SIGINT! Process A Process B SIGINT

func can be a custom function, or it can be: SIG_DFL: restore default Signal redirection Process B Process A SIGINT Run ! func signal(SIGINT, ) func func can be a custom function, or it can be: SIG_DFL: restore default SIG_IGN: ignore signal

Demo

Files vs File Descriptors File: A computer resource that allows a program to store information durably (persists even after the program finishes executing). File Descriptor (FD): An integer value that is used to reference a particular file. A process gets a file descriptor when it OPENs a file. FILE: A handy wrapper around a file descriptor, adding buffering and other features Get an FD → int open(char *filename,…) Get a FILE → FILE *fopen(char *filename,…) Get FD from FILE → int fileno(FILE *stream);

File descriptors When a process starts, it get FDs 0-2 opened Kernel File Table stdin stdout Process File Table stderr FD a.txt When a process starts, it get FDs 0-2 opened b.txt 1 2

File descriptors cont. >> open(“b.txt”, O_CREAT|O_WR) Kernel File Table stdin Process File Table stdout >> open(“b.txt”, O_CREAT|O_WR) stderr FD a.txt b.txt 1 2 3

dup The dup(int oldfd) system call creates a copy of the file descriptor oldfd, using the lowest-numbered unused file descriptor for the new descriptor.

Now we have another reference to stdout dup example Kernel File Table stdin >> dup(1) Now we have another reference to stdout Process File Table stdout stderr FD a.txt b.txt 1 2 3 4

dup2 The dup2(int oldfd, int newfd) system call performs the same task as dup(), but instead of using the lowest-numbered unused file descriptor, it uses the file descriptor number specified in newfd. If the file descriptor newfd was previously open, it is silently closed before being reused.

>> dup2(3, 1) dup2 example Kernel File Table stdin stdout Process File Table stderr FD a.txt b.txt 1 2 3 4