1. What is a Socket File?
✅ Definition:
A socket file is a special type of file used for inter-process communication (IPC) on the same machine (Unix domain sockets). It allows processes to exchange data, similar to network sockets, but without using the network stack.
📍Location & Format:
Usually found in /tmp, /var/run, etc.
Appears with s as the file type in ls -l output.
🔍 Example:
$ ls -l /var/run/docker.sock
srw-rw---- 1 root docker 0 Jun 23 09:12 /var/run/docker.sock
s → socket
Used by docker CLI to talk to the dockerd daemon.
🔧 Use Cases:
Communication between Nginx and PHP-FPM
Communication between system daemons and CLI tools
Docker: /var/run/docker.sock
📌 Create a Socket (manually):
# Python example using Unix domain socket
import socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.bind("/tmp/mysocket")
🎛️ 2. What is a Character File (Character Device)?
✅ Definition:
A character file (or character device) represents a hardware device that can be accessed as a stream of characters (bytes)—one at a time.
It does not buffer large blocks of data like block devices (e.g., disks).
📍Location & Format:
Found in /dev/, like /dev/tty, /dev/null, /dev/zero
Appears with c as the file type in ls -l
🔍 Example:
$ ls -l /dev/tty
crw-rw-rw- 1 root root 5, 0 Jun 23 09:45 /dev/tty
c → character device
5, 0 → major and minor numbers (used by kernel to identify driver)
🔧 Use Cases:
/dev/tty: Terminal
/dev/null: Discard all input
/dev/random, /dev/urandom: Random number generators