Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Section 3 Syscalls, I/O, Signals February 3rd, 2017 Taught by Josh Don."— Presentation transcript:

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

2 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

3 List of Signals

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

5 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

6 Demo

7 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);

8 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

9 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

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

11 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

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

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


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

Similar presentations


Ads by Google