How Devices Communicate | Introduction to Operating Systems

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

← 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 →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

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.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

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.

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?
A device controller is hardware attached to the device, while a device driver is software in the operating system that tells the controller what to do. The controller has its own small memory and registers and turns bits into motor movements, light pulses or radio waves. The driver translates general requests, such as write these bytes, into the exact register settings that controller expects.
What is the difference between buffering, caching and spooling?
Buffering holds data temporarily on its way somewhere, caching keeps a copy of already used data in faster memory for repeat use, and spooling queues whole jobs for a device that handles one job at a time. Video downloaded a few seconds ahead of playback is a buffer, recently read disk blocks kept in RAM are a cache, and a print queue is a spool.
What does spooling stand for?
Spool is short for simultaneous peripheral operations on-line. A spooler places whole jobs in a queue, on disk or in memory, and sends them to a one-job device such as a printer one by one, in first-in, first-out order. Programs hand over their jobs at once and carry on, outputs do not get mixed together, and a waiting job can still be deleted from the queue.
What are /dev/null and /dev/zero in Linux?
Both are special character device files on Linux, macOS and other Unix-like systems. Anything written to /dev/null is discarded, while reading /dev/zero returns an endless supply of zero bytes. Neither involves real hardware, yet programs open, read and write them with the same system calls used for ordinary files, which reflects the Unix idea that everything is a file.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

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

Introduction to Operating Systems
3 credits · NCCRS
Enroll →