Systems Programming/ C and UNIX
|
|
- Mark Barber
- 6 years ago
- Views:
Transcription
1 Systems Programming/ C and UNIX A. Fischer CSCI 4547 / 6647 November 1, 2013 A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
2 Outline 1 Signals for Threads Signals 2 Signal Handling for Processes Signals and Waits 3 What is time? 4 Unix Time Representations of Time Time Functions A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
3 Signals and Threads Signals for Threads Signal Basics Listening for and Sending Signals Condition Variables A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
4 Signals for Threads Signals Signal Basics Code example: sigthread.c A signal is an integer code sent from one process or thread to another. A particular process decides which signals it will respond to. Those signals are defined by adding them individually to a signal set. A thread can wait() until it receives a signal from the defined set. An if statement is used to implement a signal handler for each member of the set. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
5 Signals for Threads Defining and Using a Signal Set Signals Code example: sigthread.c sigset_t set; // Set of signals we will catch sigemptyset(&set); // Initialize opaque-type object. sigaddset(&set, SIGQUIT); // Quit signal. sigaddset(&set, SIGUSR1); // User-defined sig 1 rc = pthread_sigmask(sig_block, &set, NULL); A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
6 Signals for Threads Signals Defining and Using a Signal Set 2 The pthread_sigmask() function examines and/or changes the calling thread s signal mask. The first parameter specifies what to set the signal mask to: SIG_BLOCK: Union of the current mask and set. SIG_SETMASK: set. SIG_UNBLOCK: Intersection of the current mask and the complement of set. If set is not NULL, it specifies a set of signals to be modified SIGKILL and SIGSTOP cannot be blocked, and will be silently ignored if included in the sig- nal mask. Return values: If successful, pthread_sigmask() returns 0. Otherwise, an error code is returned. It fails if the enum constant is not one of those defined. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
7 Signals for Threads Signals Listening for Signals Code example: sigthread.c pthread_kill sends a signal to a specified thread. In the child thread: rc = sigwait( &set, &rc ); In the parent thread: // Wake up all the children for(t=num_threads-1; t>= 0; t--){ sleep(1); pthread_kill( threads[t], SIGQUIT ); } A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
8 A User-defined Signal Signals for Threads Signals Code example: badthread.c In main() pthread_kill( threads[2], SIGUSR1 ); In the child thread: rc = pthread_sigmask(sig_block, &set, NULL); rc = sigwait( &set, &sig ); if (sig == SIGUSR1) printf("oh Mama! It s me, thread #%ld! That hurts.\n", tid); else printf("hello Mama! It s me, thread #%ld! I just woke up.\n", tid); A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
9 Signal Handling for Processes Signal Handling for Processes Signals Catching Signals Handling the Signal A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
10 Signal Handling for Processes Signals Signals allow the manipulation of a process from inside itself, from its children, or from outside its domain. Some signals cause termination of a process. They might result from an irrecoverable error or from a user typing the interrupt character. Other signals provide information, rather than cause termination. They are used when the status of processes changes, or when input is ready at the control terminal. The SIGKILL and SIGSTOP signals cannot be caught or ignored. They are received and processed by the kernel. It is not possible to redefine the way they are handled. Several signals (such as SIGINT) have default handlers that terminate the process, others do not have a default action. kill -CODE pid sends the signal CODE to the process pid. kill pid means the same thing as kill -TERM pid A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
11 Signal Handling for Processes Traditional Meanings of Signals Many signals have customary interpretations, but a programmer can redefine their meanings. SIGKILL: Terminate the process immediately; it is out of control and not responding to normal signals. SIGSTOP: Pause a process until SIGCONT is received. SIGSTP ( Z): Sent to a process by its controlling terminal when the user asks to suspend the process. SIGINT ( C): Terminate the process gracefully. SIGTERM: Terminate the process gracefully, i.e. flush buffers, ask the user if he wishes to save his files, and close the files. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
12 More Signal Codes Signal Handling for Processes These signals can all be caught and redefined. Their default meanings are listed. SIGQUIT SIGALRM SIGHUP quit program and generate a dump terminate process; real-time timer expired terminate process; terminal line hangup SIGCHLD SIGBUS SIGSEGV child status has changed bus error segmentation violation SIGUSR1 User defined signal 1 SIGUSR2 User defined signal 2 A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
13 Signal Handling for Processes Catching Signals: siggy Many system-defined signals will terminate the process if they are not caught and handled. In the demo program, both the producer and consumer processes catch SIGINT. Catching and handling the signal requires three actions: Define the function that processes the signal. Define a signal handling structure. Attach the structure to the signal you want to catch. The program siggy shows how to set up these three parts. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
14 Signal Handling for Processes The Signal-handling Structure We need an object of type sigset_t to use as a mask. sigset_t emptyset; // Create a signal set. sigemptyset(&emptyset); // Initialize it to empty. Define an object of type struct sigaction: struct sigaction newact; newact.sa_handler = breakhandler; // handler to use newact.sa_mask = emptyset; // signals to disable newact.sa_flags = 0; // 0 = default Attach the action to the interrupt code: sigaction(sigint, &newact, NULL); // interrupt signal A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
15 Signal Handling for Processes Signal Handlers The function that processes the signal is normally short, and a lot like an exception handler. Many signal handlers supply user information and terminate the process. Others set memory variables that will enable the process to continue meaningfully. The parameter to the handler-function is the code number of the signal that was sent. Depending on what the handler does, it may not work properly to use high-level IO or any other library functions that have internal state. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
16 Signal Handling for Processes siggy s Signal Handler In siggy, we demonstrate the quick exit. This process prints a message using low-level output and writing to stderr. siggy s main loop (line 32) prints an infinite series of +. until the user types C to generate a SIGINT. When that interrupt happens, the breakhandler is called and siggy exits with an error code (1). void breakhandler(int sig) { char* message = " Process interrupted.\n"; write(2, message, strlen(message)); exit(1); } A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
17 Using sigwait() Signal Handling for Processes Signals and Waits The sigtest demo shows what happens when we reenter execution after catching a signal. We call sigwait() to put the process into a blocked state. To do so, we must define the set of signals that can end the wait. We need a sigset_t object: sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGINT); If we wanted to wake up for more than one reason, we could add more signal-types to the sigset. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
18 Signal Handling for Processes Signals and Waits Catch, Handle, and Continue The sigtest demo shows the ugly interaction between signals and waits. This function catches the signal, sets a flag to say that it happened, and writes to stderr. It does NOT kill the process. void siginthandler(int sig) { flag = true; printf(" Signal %d received\n", sig); } When a signal handler returns, control goes back to wherever it was when the signal happened. In sigtest, we prompt the user twice to enter a SIGINT. The first time we are executing an output loop, the second time we are in a sigwait(). A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
19 Signal Handling for Processes Signals and Waits The Strange Behavior of sigtest On lines 44-45, we prompt the user for a signal, then execute a busy wait until the signal happens. Busy waits keep the CPU busy doing useless work. They should be avoided because they can severely damage performance in an application that uses multiple concurrent processes or threads. When the signal comes, the handler catches it and sets the flag. Then we leave the busy wait loop and provide feedback. Note that the flag has been set. After the second prompt (line 50), we call sigwait() and block. When the signal comes, it wakes us up but it DOES NOT call the signal handler. (The flag is not set.) This uncontrollable and unpredictable behavior makes signals very tricky to use. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
20 What is time? What is time? Real Time and Elapsed Time Universal Time Time Accuracy A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
21 What is time? Real Time and Elapsed Time We use the word time in two ways: When: at what point in the history of the universe did an event take place. What time is it now? I will use time or clock time or real time to talk about when. How long: how many time units elapsed between the beginning and the end of an event? I will call this elapsed time. This seems like a simple subject but it is truly NOT simple. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
22 What is time? Universal Time We have to measure a physical phenomenon, like time, before we can talk about it, store it, or use it. The world has an official time standard, maintained by a standards committee. It is based on astronomical observations and the UT1 is one form of Universal time, established by measuring the Earth s movement relative to a distant quasar. It is the same if measured anywhere on earth. The problem is that Earth s rotation is slightly irregular. UTC, or Coordinated Universal Time is measured using a completely regular atomic clock. It approximates UT1 and is the basis for world-wide civil time. This is kept synchronized with UT1 by adding leap-seconds to the UTC clock when the drift reaches.9 seconds. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
23 What is time? Time Accuracy We set our clocks from some Universal Time reference clock, and hope they stay accurate. Any clock could be off in two ways: Drift: A clock could run a bit too fast or a bit too slow, or irregularly, and thus differ from the actual global time standard by some number of time units. Resolution: A time could be exactly on the global time standard, but be expressed in units that offer little precision. A measurement in seconds is less precise than a measurement in nanoseconds. When we record a real-time value, it might be recorded in an absolute frame of reference (UTC, or Universal Time) or in a relative frame of reference (Eastern Standard Time). A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
24 What is time? Drift Are our clocks always right? If a clock loses power and stops, it must be reset before it can be used at all. When the seasons change, clocks are set forward or back for daylight savings time. If a clock s time drifts gradually, it must be reset eventually. However, the drift may be small and not be noticed or corrected for a while. When a clock is corrected, its time suddenly jumps forward or back. People can cope with these changes. Computers cope less well. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
25 What is time? Resolution What units do we use to measure time? Years? Good enough for ages. Days? Good enough for due dates. Seconds? Good enough for most human work, and to time program execution on a Commadore-64 The system s software clock measures time in jiffies:.01 to.001 seconds, depending on the version of your kernel. Microseconds? Appropriate for timing events at the scale of today s CPU. Modern computers are able to measure time at this resolution. The resolution of our clocks and timers must be meaningful for the measurement task. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
26 Unix Time Unix Time System Time How Time is Used in Unix Representations of Time A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
27 Unix Time System Time Most computers have a battery-powered hardware clock that the system reads at boot time in order to initialize the system s software clock. The software clock defines the system time. Unix systems run a daemon that constantly communicates using the SNTP protocol (Simple Network Time Protocol) to stay synchronized with the official network time authority. The system clock is adjusted to conform to the network clock. It could be set either forward or backward. It is probable that some of the protocols will slow down a clock that is too fast, until it comes into synchrony with the standard. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
28 System Time Unix Time Star time Global time International Telecommunication Union Network Time System Time A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
29 Unix Time How Time is Used in Unix Unix uses an absolute coordinate system that is based on global time. Each file has a creation time, a time of last modification, and a time of last access, recorded in system time. File times are the basis for maintaining consistency and currency among related files and file systems. cron jobs are executed automatically to do tasks such as backup at specific system times. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
30 Unix Time How Intervals are Used in Unix Each process maintains a total elapsed time, the total execution time of system calls, and the total execution time of the user code, including all daughter threads, and excluding system calls. Execution time is used for time-sharing the CPU, for measuring performance and for charging customers on shared commercial systems. Modern systems support measurement of microsecond intervals, some smaller. Intervals are used to end timeouts (sleep). A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
31 Unix Time Mirrors and Backups These programs use date the of last modification of a file. rsync is a brilliant algorithm developed by Andrew Tridgell. It is capable of maintaining a backup mirror of a directory either locally or remotely over the network. The number of bytes that must be transmitted is minimized by sending differences, not whole files. I use the rsync command constantly to move files from one to another of my four personal machines. rsync machine1:source/ machine1:destination/ I can push files from here to elsewhere, or pull from there to here. rsync. machine2:destination/ rsync machine1:source/. My home file directory is backed up automatically each night by a cron job running rdiff-backup, which is based on the rsync library. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
32 Unix Time Problems with Time Because our time tools are not perfect Recorded Unix times are absolute, but they are displayed in local time coordinates. A translation must therefore be done each time a date is displayed. A time recorded by non-unix-aware software might be in a relative, not absolute, coordinate system. The real time, recorded simultaneously on two different Unix machines, might be different if one is not connected to the internet. Systems like rsync rely on the accuracy of the timestamps of files on two different machines. If one machine is off, the software cannot work properly. When the local time is adjusted to synchronize with network time, it might need to go backwards. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
33 Unix Time Representations of Time Representations of Time and Date The basic Unix times representation is an integer type, time_t, giving milliseconds since Jan 1, 1970 Negative date values go back to December 13, On February 13, 2009 at 23:31:30 (UTC) the Unix time was Worldwide, people had parties to celebrate this event. Currently, type time_t is the same length as a long int. This representation will be good until January 19, Before then, the Unix world will need to begin using more than 4 bytes for a date. Already, our hardware is beginning to support 8-byte integers. Also, we already need a finer mesh than milliseconds. So... it will change and we don t know when. So... don t rely on any particular implementation use type time_t and library functions to process dates.. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
34 The Time Structure Unix Time Representations of Time A secondary time representation is broken down into readable fields: #include <time.h> struct tm { int tm_sec; // seconds int tm_min; // minutes int tm_hour; // hours int tm_mday; // day of the month int tm_mon; // month int tm_year; // year int tm_wday; // day of the week int tm_yday; // day in the year int tm_isdst; // daylight saving time }; Standard functions are used to convert between time_t and struct tm. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
35 High-resolution Time Unix Time Representations of Time The timespec structure is normally used in combination with time_t to provide finer resolution for binary times. struct timeval { // defined in <sys/time.h> time_t tv_sec; // seconds since Jan suseconds_t tv_usec; // and microseconds }; struct timespec { // defined in <time.h> time_t tv_sec; // Seconds since 00:00:00 GMT Jan 1, 1970 long tv_nsec; // Additional nanoseconds since then } timespec_t; A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
36 More Time Definitions Unix Time Representations of Time useconds_t // defined in <unistd.h> an integer rep for microseconds that depends on the hardware. struct timezone { int tz_minuteswest; int tz_dsttime; }; // defined in <sys/time.h> // of Greenwich // type of dst correction to use struct itimerval { // defined in <sys/time.h> struct timeval it_interval; // timer interval struct timeval it_value; // current value }; A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
37 Unix Time Time Functions Time Functions All of these are in time.h. System time is stored as UTC (Coordinated Universal Time) time_t now = time( NULL ); // Read the system clock. Once you have a time_t, it can be converted to and from other forms using library functions: struct tm nowstruct = localtime( now ); struct tm nowstruct = gmtime( now ); These two formats can be converted to printable strings: char nowstring[25] = ctime( now ); char* now2 = asctime( &nowstruct ); tools contains a set of functions to extract the date (today()) and time (oclock()) separately. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
38 Unix Time Time Functions Time Functions Use these variables: time_t time1, time2, elapsed; struct tm timestr; Convert from struct to integer format in current time zone: time1 = mktime( ×tr ); Convert from struct to integer format in UTC time: time1 = timegm( ×tr ); Interval from time1 to time2, in seconds. elapsed = difftime(time2, time1); A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
39 Unix Time Time Functions Functions for Formatting Times Use these variables: int resultlength; struct tm timestr; char *st; char buffer[25]; Format the time, producing a string. (Like a Java tostring().) See man page for format details. resultlength = strftime(buffer, 25, format, &imestr); The opposite operation from strftime(). Parse the string st, according to the format given, and fill in the fields of timestr. Return a pointer to the first character in st that has not been converted. st = strptime( st1, "%H:%M:%S", ×tr); A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
40 Hi-res Time Functions Unix Time Time Functions useconds_t ualarm( useconds_t, useconds_t ); A simplified interface to setitimer The first argument is the total lifetime of this timer. The second argument is the frequency at which the alarm should ring. int usleep( useconds_t usecs ); suspend thread execution for usecs microseconds int nanosleep( const struct timespec *rqtp, struct timespec *rmtp); suspend thread execution for rqtp nanoseconds The interval may be slightly longer, but will be as close as the system hardware can measure the interval. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
41 Unix Time Time Functions Adding and Subtracting Hi-Res Times The C libraries do not contain functions for adding and subtracting hi-res times. The code for working on microsecond-times is given at this website: libc Elapsed time This code can be easily modified to work on nanosecond-times. Basically, an addition or subtraction is done on the microsecond member of the timeval, and if that overflows, a carry is added to the member representing seconds. A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture /41 November 1, / 41
Systems Programming/ C and UNIX
Systems Programming/ C and UNIX A. Fischer CSCI 4547/6647 What is Time? November 6, 2017 A. Fischer CSCI 4547/6647[1ex]What is Time? Systems Programming Lecture 8... 1/24 November 6, 2017 1 / 24 Outline
More informationSystems Programming/ C and UNIX
Systems Programming/ C and UNIX A. Fischer CSCI 4547 / 6647 November 16, 2017 A. Fischer CSCI 4547 / 6647 Systems Programming Lecture 8... 1/20 November 16, 2017 1 / 20 Outline 1 Signals for Threads Signals
More informationOverview of Time Related Data Structures and Functions in Unix/C. It s About Time
Overview of Time Related Data Structures and Functions in Unix/C It s About Time 1. time_t Same as an unsigned long. Time in seconds since Midnight GMT Jan 1, 1970. a. char * ctime(time_t x) will return
More informationCSci 4061 Introduction to Operating Systems. (Advanced Control Signals)
CSci 4061 Introduction to Operating Systems (Advanced Control Signals) What is a Signal? Signals are a form of asynchronous IPC Earlier: Non-blocking I/O and check if it has happened => polling Problem
More informationLecture 7: Signals and Events. CSC 469H1F Fall 2006 Angela Demke Brown
Lecture 7: Signals and Events CSC 469H1F Fall 2006 Angela Demke Brown Signals Software equivalent of hardware interrupts Allows process to respond to asynchronous external events (or synchronous internal
More informationCSE 421: Introduction to Operating Systems
Recitation 5: UNIX Signals University at Buffalo, the State University of New York October 2, 2013 About Me 4th year PhD student But TA first time From South Korea Today, We will study... What UNIX signals
More informationExamination C++ Programming
LUND INSTITUTE OF TECHNOLOGY 1(8) Department of Computer Science Examination C++ Programming 2011 08 20, 8.00 13.00 Aid at the exam: one C++ book. The copies of the lecture slides are not allowed. You
More informationLesson 3. The func procedure allows a user to choose the action upon receipt of a signal.
Lesson 3 Signals: When a process terminates abnormally, it usually tries to send a signal indicating what went wrong. C programs can trap these for diagnostics. Software interrupts: Stop executing the
More informationOverview. POSIX signals. Generation of signals. Handling signals. Some predefined signals. Real-time Systems D0003E 3/3/2009
Overview Real-time Systems D0003E Lecture 13: More on inter-process communication (Burns & Wellings ch. 8, 11 & 10.6) Posix signals Posix timers timers in cygwin (lab environment) event-loop pattern semaphores
More informationCSC209H Lecture 8. Dan Zingaro. March 4, 2015
CSC209H Lecture 8 Dan Zingaro March 4, 2015 Signals you Already Know Like pipes, signals are a form of inter-process communication You ve already sent signals using the shell When you hit ctrl+c to terminate
More informationInteracting with Unix
Interacting with Unix Synopsis Getting the Process ID #include pid_t getpid(void); Example: #include #include int main(){ pid_t n = getpid(); printf("process id is %d\n",
More informationTimekeeping. 5February :09
Timekeeping UNIX timekeeping is an untidy area, made more confusing by national and international laws and customs. Broadly, there are two kinds of functions: one group is concerned with getting and setting
More informationCS 33. Signals Part 1. CS33 Intro to Computer Systems XXII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.
CS 33 Signals Part 1 CS33 Intro to Computer Systems XXII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Whoops $ SometimesUsefulProgram xyz Are you sure you want to proceed? Are you really sure?
More informationSignals. CSC209: Software Tools and Systems Programming. Furkan Alaca & Paul Vrbik
Signals CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 9 Acknowledgement These slides are built upon material
More informationECE 650 Systems Programming & Engineering. Spring 2018
ECE 650 Systems Programming & Engineering Spring 2018 User Space / Kernel Interaction Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Operating System Services User and other
More informationSignals. Joseph Cordina
1 Signals Signals are software interrupts that give us a way to handle asynchronous events. Signals can be received by or sent to any existing process. It provides a flexible way to stop execution of a
More informationOperating Systems 2010/2011
Operating Systems 2010/2011 Signals Johan Lukkien 1 Signals A signal is a software generated event notification of state change encapsulation of physical event usually: sent from a process to a process
More informationReal Time Operating Systems and Middleware
Real Time Operating Systems and Middleware Real-Time Programming Interfaces Luca Abeni abeni@dit.unitn.it Real Time Operating Systems and Middleware p. 1 Needs for a Real-Time Interface Real-Time applications
More informationProcesses. Processes (cont d)
Processes UNIX process creation image-file arg1 arg2 Shell command line example ls -l Equivalent to /bin/ls -l Why? How do you find out where the image file is? Background processes ls -l & Execute a process
More informationEmbedded Systems Programming
Embedded Systems Programming Signaling (Module 24) Yann-Hang Lee Arizona State University yhlee@asuedu (480) 727-7507 Summer 2014 Signals A signal is an event generated by OS in response to some condition
More informationChapter 4 Multithreaded Programming
Chapter 4 Multithreaded Programming Da-Wei Chang CSIE.NCKU Source: Abraham Silberschatz, Peter B. Galvin, and Greg Gagne, "Operating System Concepts", 9th Edition, Wiley. 1 1 Outline Overview Multithreading
More informationSignals. POSIX defines a variety of signal types, each for a particular
Signals A signal is a software interrupt delivered to a process. The operating system uses signals to report exceptional situations to an executing program. Some signals report errors such as references
More informationSystem Programming. Signals I
Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 3 Signals
More informationUnix System Programming - Chapter 8
Unix System Programming - Chapter 8 Neal Nelson The Evergreen State College Apr 2010 USP Chapter 8 - Signals Section 8.1 - Basic Signal Concepts Section 8.2 - Generating Signals Section 8.3 - Signal Masks
More informationSYSTEM INFORMATION. UNIX Programming 2015 Fall by Euiseong Seo
SYSTEM INFORMATION UNIX Programming 2015 Fall by Euiseong Seo Host Information POSIX defines host information as follows OS name (Linux) OS release (3.13.0) OS version (#60-Ubuntu SMP Web Aug 13) Node
More informationCS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18
CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 18 LAST TIME: OVERVIEW Expanded on our process abstraction A special control process manages all other processes Uses the same process abstraction
More informationA read or write being atomic means that its effect is as if it happens instantaneously.
A read or write being atomic means that its effect is as if it happens instantaneously. Signals are a kernel-supported mechanism for reporting events to user code and forcing a response to them. There
More informationComputer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012
Computer Science 330 Operating Systems Siena College Spring 2012 Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012 Quote: UNIX system calls, reading about those can be about as
More informationKING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 6
Objective: KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 6 Inter-Process Communication (IPC) using Signals Now that we know
More informationF28HS Hardware-Software Interface: Systems Programming
: Systems Programming Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh Semester 2 2017/18 0 No proprietary software has been used in producing these slides
More informationSystem Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch
System Calls and Signals: Communication with the OS Jonathan Misurda jmisurda@cs.pitt.edu System Call An operation (function) that an OS provides for running applications to use CS 1550 2077 strace./hello
More informationSignals are a kernel-supported mechanism for reporting events to user code and forcing a response to them. There are actually two sorts of such
Signals are a kernel-supported mechanism for reporting events to user code and forcing a response to them. There are actually two sorts of such events, to which we sometimes refer as exceptions and interrupts.
More informationProcess Control. Philipp Koehn. 23 April 2018
Process Control Philipp Koehn 23 April 2018 Control Flow 1 The CPU executes one instruction after another Typically, they are next to each other in memory (unless jumps, branches, and returns from subroutine)
More informationAcontecimentos assíncronos (POSIX signals) Sincronização com múltiplos acontecimentos
Acontecimentos assíncronos (POSIX signals) Sincronização com múltiplos acontecimentos 1 Rotinas assíncronas POSIX Signals n Condições normais e excepções Signal SIGABRT SIGALRM SIGFPE SIGHUP SIGILL SIGINT
More informationCOSC243 Part 2: Operating Systems
COSC243 Part 2: Operating Systems Lecture 16: Threads and data sharing Zhiyi Huang Dept. of Computer Science, University of Otago Zhiyi Huang (Otago) COSC243 Lecture 16 1 / 24 Overview Last lecture: Hierarchical
More informationOperating Systems. Threads and Signals. Amir Ghavam Winter Winter Amir Ghavam
95.300 Operating Systems Threads and Signals Amir Ghavam Winter 2002 1 Traditional Process Child processes created from a parent process using fork Drawbacks Fork is expensive: Memory is copied from a
More informationSo far, we know how to create processes. How do we communicate with them? Primary mechanism: signals
Signals Page 1 Signals and handlers Thursday, September 14, 2017 11:58 AM So far, we know how to create processes. How do we communicate with them? Primary mechanism: signals Vocabulary Thursday, September
More informationProcess. Signal #8. Signals are software interrupts from unexpected events. a power failure. an alarm clock. the death of a child process
Linux/UNIX Programming 문양세강원대학교 IT특성화대학컴퓨터과학전공 Signals Signals are software interrupts from unexpected events an illegal operation (e.g., divide by 0) a power failure an alarm clock the death of a child
More informationProcess management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)
Process management CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska lazowska@cs.washington.edu Allen Center 570 This module begins a series of topics on processes, threads, and synchronization
More informationGoals of this Lecture
Signals 1 Goals of this Lecture Help you learn about: Sending signals Handling signals and thereby How the OS exposes the occurrence of some exceptions to application processes How application processes
More informationCSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476
CSE 451: Operating Systems Winter 2015 Module 4 Processes Mark Zbikowski mzbik@cs.washington.edu Allen Center 476 2013 Gribble, Lazowska, Levy, Zahorjan Process management This module begins a series of
More informationCOMP 2400 UNIX Tools
COMP 2400 UNIX Tools Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Time is Relative Timezones, DST Y2K February 29th, leap seconds US Congress Precision (s, ms, ns?) 2 time
More informationCSCI 4061: Signals and Signal Handlers
1 CSCI 4061: Signals and Signal Handlers Chris Kauffman Last Updated: Thu Oct 19 12:16:40 CDT 2017 2 Logistics Reading Robbins and Robbins Ch 8.1-8.7, 9.1-2 OR Stevens/Rago Ch 10 Goals Sending Signals
More informationSystem Calls & Signals. CS449 Spring 2016
System Calls & Signals CS449 Spring 2016 Operating system OS a layer of software interposed between the application program and the hardware Application programs Operating system Processor Main memory
More informationCSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534
CSE 410: Computer Systems Spring 2018 Processes John Zahorjan zahorjan@cs.washington.edu Allen Center 534 1. What is a process? Processes 2. What's the process namespace? 3. How are processes represented
More informationSignals: Management and Implementation. Sanjiv K. Bhatia Univ. of Missouri St. Louis
Signals: Management and Implementation Sanjiv K. Bhatia Univ. of Missouri St. Louis sanjiv@aryabhat.umsl.edu http://www.cs.umsl.edu/~sanjiv Signals Mechanism to notify processes of asynchronous events
More informationLecture 4 Threads. (chapter 4)
Bilkent University Department of Computer Engineering CS342 Operating Systems Lecture 4 Threads (chapter 4) Dr. İbrahim Körpeoğlu http://www.cs.bilkent.edu.tr/~korpe 1 References The slides here are adapted/modified
More informationOverview. Administrative. * HW 1 grades. * HW 2 Due. Topics. * 5.1 What is a Signal? * Dealing with Signals - masks, handlers
Overview Administrative * HW 1 grades * HW 2 Due Topics * 5.1 What is a Signal? * 5.2-3 Dealing with Signals - masks, handlers * 5.4 Synchronization: pause(), sigsuspend() * 5.6 Interaction with other
More informationSignals and Session Management. Signals. Mechanism to notify processes of system events
Signals and Session Management Signals Mechanism to notify processes of system events Primitives for communication and synchronization between user processes Signal generation and handling Allow an action
More informationPreview. The pause() System Call. The pause() System Call. The signal() System Call 10/18/2017
Preview The pause() System Call The pause() System call The signal() system call Signal set The sigprocmask() system call The sigaction() system call The sigsuspend() system call The abort() system call
More informationPROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)
MANAGEMENT OF APPLICATION EXECUTION PROCESS CONTROL BLOCK Resources (processor, I/O devices, etc.) are made available to multiple applications The processor in particular is switched among multiple applications
More informationSignals, Synchronization. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han
, Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han Announcements Program Assignment #1 due Tuesday Feb. 15 at 11:55 pm TA will explain parts b-d in recitation Read chapters 7 and
More informationShell Execution of Programs. Process Groups, Session and Signals 1
Shell Execution of Programs Process Groups, Session and Signals 1 Signal Concepts Signals are a way for a process to be notified of asynchronous events (software interrupts). Some examples: a timer you
More informationPreview. Process Termination. wait and waitpid() System Call. wait and waitpid() System Call. waitpid() System Call 10/23/2018
Preview Process Termination The waitpid() System Call The system() System Call Concept of Signals Linux Signals The signal System Call Unreliable Signals Signal() System Call The kill() and raise() System
More informationAvoid Using POSIX time_t for Telling Time
Avoid Using POSIX time_t for Telling Time John Sauter 2018-07-15 Abstract The POSIX data type time_t is defined in a way that leads to errors in application programs when it is used for telling time. Here
More informationSMD149 - Operating Systems
SMD149 - Operating Systems Roland Parviainen November 3, 2005 1 / 45 Outline Overview 2 / 45 Process (tasks) are necessary for concurrency Instance of a program in execution Next invocation of the program
More informationComputer Science & Engineering Department I. I. T. Kharagpur. Operating System: CS rd Year CSE: 5th Semester (Autumn ) Lecture VII
Computer Science & Engineering Department I. I. T. Kharagpur Operating System: CS33007 3rd Year CSE: 5th Semester (Autumn 2006-2007) Lecture VII Goutam Biswas Date: 4th September, 2006 1 Signals Signals
More informationSignals! Goals of this Lecture! Help you learn about:" Sending signals" Handling signals"
Signals! 1 Goals of this Lecture! Help you learn about: Sending signals Handling signals and thereby How the OS exposes the occurrence of some exceptions to application processes How application processes
More informationProcess Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal
Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal 2012-10-01 what is a process? an abstraction! you can think of it as a program in the midst of
More informationPrograms. Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic
Programs Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic Types of Processes 1. User process: Process started
More informationIMPLEMENTATION OF SIGNAL HANDLING. CS124 Operating Systems Fall , Lecture 15
IMPLEMENTATION OF SIGNAL HANDLING CS124 Operating Systems Fall 2017-2018, Lecture 15 2 Signal Handling UNIX operating systems allow es to register for and handle signals Provides exceptional control flow
More informationSignals. Goals of this Lecture. Help you learn about: Sending signals Handling signals
Signals 1 Goals of this Lecture Help you learn about: Sending signals Handling signals and thereby How the OS exposes the occurrence of some exceptions to application processes How application processes
More informationOperating Systemss and Multicore Programming (1DT089)
Operating Systemss and Multicore Programming (1DT089) Problem Set 1 - Tutorial January 2013 Uppsala University karl.marklund@it.uu.se pointers.c Programming with pointers The init() functions is similar
More informationAny of the descriptors in the set {1, 4} have an exception condition pending
Page 1 of 6 6.3 select Function This function allows the process to instruct the kernel to wait for any one of multiple events to occur and to wake up the process only when one or more of these events
More informationTHE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7
THE PROCESS ABSTRACTION CS124 Operating Systems Winter 2015-2016, Lecture 7 2 The Process Abstraction Most modern OSes include the notion of a process Term is short for a sequential process Frequently
More informationOutline. Computer programming. Usage of time and date functions. Date and Time: time.h. Date and Time: time.h. Time functions:
Outline Computer programming "An expert is a man who has made all the mistakes which can be made, in a narrow field." Niels Bohr Working with time I/O redirection Variable length argument lists Command
More information* What are the different states for a task in an OS?
* Kernel, Services, Libraries, Application: define the 4 terms, and their roles. The kernel is a computer program that manages input/output requests from software, and translates them into data processing
More informationPreview. Review. System Data Files (Password File) System Data Files (Password File) System Data Files (Password File)
Review Preview link(), unlink() System Call remove(), rename() System Call Symbolic Links Symbolic link to directory Symbolic link to a executable file symlink() System Call File Times utime() System Call
More informationCS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 19
CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 19 LAST TIME Introduced UNIX signals A kernel facility that provides user-mode exceptional control flow Allows many hardware-level exceptions
More informationProcesses. CS439: Principles of Computer Systems January 24, 2018
Processes CS439: Principles of Computer Systems January 24, 2018 Last Time History Lesson Hardware expensive, humans cheap Hardware cheap, humans expensive Hardware very cheap, humans very expensive Dual-mode
More informationCSE410 Operating Systems Spring 2018 Project 1: Introduction to Unix/Linux Signals
CSE410 Operating Systems Spring 2018 Project 1: Introduction to Unix/Linux Signals 1 Overview and Background In this exercise you will gain first hand experience with Unix/Linux signals. You will develop
More informationSignals! Goals of this Lecture! Help you learn about:" Sending signals" Handling signals"
Signals! 1 Goals of this Lecture! Help you learn about: Sending signals Handling signals and thereby How the OS exposes the occurrence of some exceptions to application processes How application processes
More informationWorkshop on Inter Process Communication Solutions
Solutions 1 Background Threads can share information with each other quite easily (if they belong to the same process), since they share the same memory space. But processes have totally isolated memory
More informationTime Handling in Programming Language
CSE 237B Fall 2009 Time Handling in Programming Language Rajesh Gupta University of California, San Diego System Characteristics Complexity in function (and in size) Concurrent control of separate components
More informationComputer programming. "An expert is a man who has made all the mistakes which can be made, in a narrow field." Niels Bohr
Computer programming "An expert is a man who has made all the mistakes which can be made, in a narrow field." Niels Bohr 1 Outline Working with time I/O redirection Variable length argument lists Command
More informationExceptions, Processes and Signals
Exceptions, Processes and Signals Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Shells See https://en.wikipedia.org/wiki/shell_(computing) Instructor: Joanna Klukowska Slides adapted
More informationCSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018
CSCE 311 - Operating Systems Interrupts, Exceptions, and Signals Qiang Zeng, Ph.D. Fall 2018 Previous Class Process state transition Ready, blocked, running Call Stack Execution Context Process switch
More informationMultitasking. Programmer s model of multitasking. fork() spawns new process. exit() terminates own process
Signals Prof. Jin-Soo Kim( jinsookim@skku.edu) TA JinHong Kim( jinhong.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Multitasking Programmer s model of multitasking
More informationKilling Zombies, Working, Sleeping, and Spawning Children
Killing Zombies, Working, Sleeping, and Spawning Children CS 333 Prof. Karavanic (c) 2015 Karen L. Karavanic 1 The Process Model The OS loads program code and starts each job. Then it cleans up afterwards,
More information19: I/O Devices: Clocks, Power Management
19: I/O Devices: Clocks, Power Management Mark Handley Clock Hardware: A Programmable Clock Pulses Counter, decremented on each pulse Crystal Oscillator On zero, generate interrupt and reload from holding
More informationSystems Programming/ C and UNIX
Systems Programming/ C and UNIX Alice E. Fischer November 22, 2013 Alice E. Fischer () Systems Programming Lecture 12... 1/27 November 22, 2013 1 / 27 Outline 1 Jobs and Job Control 2 Shared Memory Concepts
More informationA process. the stack
A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes
More informationsignals Communicating with the OS System call (last lecture) Signal (this lecture) User Process Operating System
Signals 1 Communicating with the OS signals User Process Operating System systems calls System call (last lecture) o Request to the operating system to perform a task o that the process does not have permission
More informationWeek 13. Final exam review
Week 13. Final exam review 1. True or false? A. I claim that linked lists have the following advantages over the arrays: They allow insertion in the middle in a constant time They allow access to the element
More informationProgramming Assignments will be.. All the PAs are continuous 3 major factors that you should consider
Signals Prof. Jin-Soo Kim( jinsookim@skku.edu) TA - Dong-Yun Lee (dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu NOTICE Programming Assignments will be.. All
More informationProcesses. Johan Montelius KTH
Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other
More informationProcesses. CS439: Principles of Computer Systems January 30, 2019
Processes CS439: Principles of Computer Systems January 30, 2019 What We Know Operating system complexity increased over time in response to economic and technological changes The three roles did not show
More informationLecture 2: Architectural Support for OSes
Lecture 2: Architectural Support for OSes CSE 120: Principles of Operating Systems Alex C. Snoeren HW 1 Due Tuesday 10/03 Why Architecture? Operating systems mediate between applications and the physical
More informationOperating System Structure
Operating System Structure CSCI 4061 Introduction to Operating Systems Applications Instructor: Abhishek Chandra Operating System Hardware 2 Questions Operating System Structure How does the OS manage
More informationSignals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Signals Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Multitasking (1) Programmer s model of multitasking fork() spawns new process Called once,
More informationLab 4. Out: Friday, February 25th, 2005
CS034 Intro to Systems Programming Doeppner & Van Hentenryck Lab 4 Out: Friday, February 25th, 2005 What you ll learn. In this lab, you ll learn to use function pointers in a variety of applications. You
More informationPrinceton University. Computer Science 217: Introduction to Programming Systems. Signals
Princeton University Computer Science 217: Introduction to Programming Systems Signals 1 Goals of this Lecture Help you learn about: Sending signals Handling signals and thereby How the OS exposes the
More informationENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS
SOLUTIONS ENGR 3950U / CSCI 3020U (Operating Systems) Midterm Exam October 23, 2012, Duration: 80 Minutes (10 pages, 12 questions, 100 Marks) Instructor: Dr. Kamran Sartipi Question 1 (Computer Systgem)
More informationSignals and Signal Handling - Part 2
Signals and Signal Handling - Part 2 Dept. of Computer Science & Engineering 1 Some Other System Calls kill( ), raise( ) kill( ) sends a signal to a process or a group of process. raise( )sends a signal
More information18-642: Time and Date
18-642: Time and Date 2/21/2018 Date and Time Anti-Patterns for Date and Time: Daylight savings time hard-coded Time kept without handling time problems Daylight savings time, time zones, mobility Internationalization
More informationInterprocess Communication
Interprocess Communication Reading: Silberschatz chapter 4 Additional Reading: Stallings chapter 6 EEL 358 1 Outline Introduction Shared memory systems POSIX shared memory Message passing systems Direct
More information1 Introduction. 2 Managing contexts. Green, green threads of home. Johan Montelius HT2018
1 Introduction Green, green threads of home Johan Montelius HT2018 This is an assignment where you will implement your own thread library. Instead of using the operating systems threads you will create
More informationCS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20
CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to
More informationCS 470 Operating Systems Spring 2013 Shell Project
CS 470 Operating Systems Spring 2013 Shell Project 40 points Out: January 11, 2013 Due: January 25, 2012 (Friday) The purpose of this project is provide experience with process manipulation and signal
More informationCS 326: Operating Systems. Process Execution. Lecture 5
CS 326: Operating Systems Process Execution Lecture 5 Today s Schedule Process Creation Threads Limited Direct Execution Basic Scheduling 2/5/18 CS 326: Operating Systems 2 Today s Schedule Process Creation
More information