UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 5.6 Free with a free account
How Devices Communicate
Introduction to Operating Systems · Chapter 5: Peripheral Devices and I/O SystemsSection 5.6 · lesson 41 of 837 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: I/O Ports →← Device Access MethodsNext lesson: I/O Ports →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
Controllers, drivers, buffers, caches and spools, plus Unix device files.
- Distinguish a device controller from a device driver
- Compare buffering, caching and spooling by purpose
- Explain how a print spooler queues jobs for a one-job device
- Describe how Unix-like systems expose devices as files in /dev
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,053 words). Read along, or search it.
Opening Scene
Three Print Jobs, No Waiting
Sam, who runs a small online bakery, clicks print on three things in a row, and goes straight back to baking. The slow receipt printer is still working on the first page. Yet nobody was kept waiting, and nothing came out mixed up. A few quiet tricks make that happen: a translator for each device, a small waiting area for data, and a line for jobs. And on Linux, there's one more surprise. The printer, the keyboard, and even a bottomless pit are all treated as ordinary files.
Hardware Helper
The Device Controller
A device can't speak the processor's language directly. Two helpers sit in between: one in hardware, and one in software. The device controller is a small circuit board, or chip, attached to the device, with its own tiny memory and registers. It handles the electrical details, turning bits into motor movements, light pulses, or radio waves. And it reports back: busy, ready, or error.
Software Helper
The Device Driver
The device driver is software, part of the operating system, that knows one kind of controller. It translates a general request, like write these bytes, into the exact register settings that controller expects. Because the operating system talks to every driver in one common way, a new device only needs a new driver. Don't mix them up. The controller is hardware, attached to the device. The driver is software, in the OS, and it tells the controller what to do.
Quick Check
Spotting the Controller in a USB Stick
Quick check. Sam saves the day's orders to a USB stick, and three things take part. The order program that saves the file. Some kernel code that knows the stick's chip and its registers. And a chip inside the stick that writes the flash memory. Which one is the device controller? Pause, and decide. The chip inside the stick. It's hardware, attached to the device, and it turns requests into real writes to the flash. The kernel code is the tempting pick, since it knows the chip's registers. But that's the driver: software in the OS. And the order program just asks. Only the chip does the real work.
Waiting Areas
Buffering, Caching and Spooling
Devices and programs run at different speeds, so the system keeps waiting areas in RAM. Three of them are easy to confuse. All three use memory to smooth out speed differences. They differ in purpose. Buffering is a temporary holding area for data on its way somewhere. A fast sender drops data in and moves on, and a slow receiver takes it out at its own pace. Then it's forgotten. Caching keeps a copy of data you've already used, in faster memory, in case it's wanted again. The original stays where it was. The OS keeps recently read disk blocks in RAM this way, much like the CPU cache from lesson 4.9. And spooling serves a device that can handle only one job at a time, like a printer. Whole jobs wait in a queue, on disk or in memory, and go to the device one by one. Spool is short for simultaneous peripheral operations on-line.
Print Queue
First In, First Out Jobs
Here's the print queue as a picture. Three jobs go in: the order list, receipt number forty-one, and a label sheet. All three are handed over before anything prints, so the program never waits. Then the printer works through the line, one job at a time. The order list prints first, because it went in first. First in, first out. Without a spooler, the second program would have to stop until the first finished. Or worse, its text could land in the middle of the first one's page.
Real Case
Deleting a Job Before It Prints
Sam once spotted a typo in a price, just after clicking print. Closing the order program didn't stop it: the job was already in the queue. Ivy, who looks after the computers at a school, opened the queue, found the job still waiting behind two others, and deleted it before it reached the printer. That's the point of a spool, she said. Jobs wait in a line you can see and change. A page already on paper can't be called back.
Quick Check
Video Seconds Held Ahead
Quick check. A video app downloads the next ten seconds of a show ahead of time, so playback doesn't stutter when the network slows down. Once those seconds have played, they're thrown away. Is that memory a cache, a spool, or a buffer? Pause, and decide. A buffer. The data is on its way, from a bursty network to a steady player, and it's forgotten once it's used. A cache is tempting, because the data sits in memory. But a cache keeps a copy for a repeat, and nobody re-reads those seconds. And a spool holds whole jobs, for a one-at-a-time device.
Device Files
Devices as Files in Slash Dev
Now the surprise. On Linux, and on a Mac too, each device gets a name in a folder called slash dev. Programs open, read, and write it with the same system calls they use for ordinary files, from lesson 2.3. That's what people mean by: on Unix-like systems, everything is a file. Two special devices exist on every such system. Slash dev slash null swallows anything written to it. Slash dev slash zero never runs dry: it supplies endless zero bytes. Neither involves real hardware, but both are driven exactly like real devices. Each device file has a major number, which picks its driver, and a minor number, which picks the device that driver manages.
Command Output
Character and Block Letters in Listings
Here's how ls dash l starts its line for three device files, on a Mac. Linux shows the same letters. The null and zero lines start with a c: a character device, from lesson 5.4. The Mac's internal disk, slash dev slash disk zero, starts with a b: a block device. Reading eight bytes from slash dev slash zero, with the ordinary head command, gives eight zero bytes. And writing text to slash dev slash null succeeds, with exit status zero. The text is simply gone. That's why the pipes and redirects from lesson 1.7 work on devices too, with no new tool for each one.
Key Takeaways
Controllers, Drivers, Queues and Files
To recap. The controller is hardware on the device. The driver is software in the OS that tells it what to do. A buffer holds data on its way. A cache keeps a copy for repeats. A spool lines up whole jobs for a one-job device. And on Unix-like systems, devices are files in slash dev, reached with the same calls as any file.
About Introduction to Operating Systems at UPI Study
Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About How Devices Communicate
What is the difference between a device driver and a device controller?
What is the difference between buffering, caching and spooling?
What does spooling stand for?
What are /dev/null and /dev/zero in Linux?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Operating Systems.
83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →