25-files-io-devices-part3 - CS241 Systems Programming...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
    CS241 Systems Programming Files, IO, devices (part 3) Yoann Padioleau
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Table of contents Interface (user side) Files, File Descriptors Special Files, Device Files, Terminal Files as a form of IPC: redirection, pipes Buffered IO, flush Files and concurrency, O_EXCL, lock, test_and_set at file level Others (mkfifo(), socket(), select(), mmap(), non blocking IO, fcntl(), ioctl(), terminal control) Implementation (kernel and hardware side) Device properties Asm in/out ports or memory mapped IO, hardware interrupt Device drivers Interrupt, polling, DMA Scheduling, kernel stack, concurrency in kernel Putting it together: tracing read()
Background image of page 2
    Problem: how to avoid 2 independent processes to access the same database on the disk ? A solution: use an empty file as a lock file , like a flag, after all the first form of IPC is to simply use files Naive code: if( exist_file (« /tmp/db-lock.empty ») { printf(«already a user»); exit(0); } else { create_file (« /tmp/db-lock.empty »); /* and now can use database files safely */ } Problem ? Solution: open(« /tmp/db-lock.empty », O_CREAT| O_EXCL ) Files and Concurrency if 2 processes executes same code and context switch (because time- slice expired) in the middle of 2 function calls
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Why it works (OS in the 90’s, 1 CPU) ? code heap stack open(« xx », O_EXCL) code heap stack Usually kernel code disables interrupts when enter kernel No context switch when in kernel in the 90’s, so syscalls were atomic By using one syscall for both checking and creating, you have a kind of atomic test_and_set () at file level (not memory level) kernel bar.exe ( P2 foo.exe ( P1 sys_open(){…} open(« xx », O_EXCL) sys_write(){…} This is temporary. If hardware interrupt then just pending
Background image of page 4
    Why it works (OS in the 00’s, 2 CPUs) ? code
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/04/2008 for the course CS 241 taught by Professor Systemsprogramming during the Spring '08 term at University of Illinois at Urbana–Champaign.

Page1 / 23

25-files-io-devices-part3 - CS241 Systems Programming...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online