Linux Programming – Part 5: Steam

Streeeeeeeaming…

Streaming is the last of the three essential concepts of the Linux world. Let’s get into it.

What is a stream?

A stream is the last section of the three most essential concepts of the Linux world. My definition of a stream is byte-streaming, a tunnel through which byte data will travel. And in the Linux world, it also indicates file reading/writing/opening/closing process. And please keep in mind, the term stream is my own definition of Linux’s procedure, so you may not find any similar words in other tech blogs or Linux textbooks.

Streaming to a file

Think about a situation where a process wants to access a file’s content. In this case, the process must request the kernel via a system call to tunnel a streaming path connecting to the target file. Through the process, the file can access and gain the file content.

image 01: file and streaming process

In the programming world, byte-data retrieval via streaming is called ‘read’ and the data-injection is called ‘write’.

Streaming to devices

There are multiple forms of data streaming. In the previous section, we’ve seen the file on the other end of the streaming line. But if it’s something to do with the byte data, anything can be streamed.

SSD, HDD, and keyboard, for example, are not exceptions. SSD and HDD, in particular, are full-fledged byte-data machines, so the system can interact with them as if they were like other files. You can consider a keyboard as a device that streams key info to its connected device.

image 02: SSD/Keyboard and streaming process

Piping

In image 03, the process and file were on the other end of the line from each other. If this is the case, how about piping the line from one process to another process via the kernel’s streaming procedure? Yes, it’s very much possible. We call it – piping.

image 03: piped streaming

Since you probably already know what piping is, yes that’s right, it’s the Linux command function that allows you to connect two different commands altogether to build a super command. And this process is considered data streaming.

Networking

As far as byte data is transferred correctly, it’s also okay to stream it between two PCs via a networking path. This is what call network communication.

image 04: network communication

IPC: Inter-Process Communication

IPC (Inter-Process Communication) defines the communication between two or more processes that exchange their data via a streaming path.

Linux’s three essential concepts

  1. File system: This is the place where you can name a file and save it.
  2. Process: This is the data-exchanging/data-handling procedure on the system.
  3. Stream: This is a method that the process uses to interact with the file system or other functions.

Leave a Reply