"To observe a process is to change it.
To attach with ptrace is to destroy it."
Welcome back to Koans from /dev/null, a series of short hacker koans inspired by Unix, systems programming, bugs, daemons, race conditions, and other non-deterministic awakenings.
These are not puzzles to solve. They're fragments from the debugger's path.
Sometimes the bug is in your code. Sometimes in your assumptions.
And sometimes, it's in the scheduler.
9. The Koan of the Vanishing Print
"Master, when I add a printf()
, the crash disappears."
"Then keep the print."
"But I don't understand why it works."
"It doesn't. You just moved the crack in the ice."
The student left the print and walked away.
Lesson: Undefined behavior does not need your permission.
10. The Koan of the Sleeping Thread
Two threads accessed the same file descriptor.
One slept.
The other wrote garbage.
The kernel didn't complain.
The scheduler just smiled.
Lesson: The system gives you tools. It does not protect you from yourself.
11. The Koan of Select()
A student implemented a socket server using select()
.
It worked in testing.
In production, it stopped responding.
"Did you check for write readiness?" asked the master.
"Only read."
The master closed the socket.
So did the kernel.
Lesson: Listening is not enough. Sometimes you must be ready to speak.
12. The Koan of the Leaked FD
A disciple ran lsof
and found thousands of open descriptors.
He wept.
"Master, where did they come from?"
"From loops without close()
."
He added close(fd)
and broke the app.
"Now nothing works."
"Good. Now you know they were not leaks. They were lifelines."
Lesson: Closing things feels safe. But safety is contextual.
13. The Koan of ptrace()
"Master, I used ptrace()
to debug the child process."
"And what happened?"
"It froze."
"So did the parent?"
"Yes."
"Then you have learned: even observation has cost."
Lesson: Every level of introspection comes with risk – in life and in ptrace.
14. The Koan of the One-Core Lock
The student wrote a lockless algorithm and tested it.
It worked flawlessly.
"Master, I am free from locks."
The master ran it on a two-core machine.
It crashed.
"Now you are free from assumptions."
Lesson: Code that works on one core is not concurrent. It is an illusion.
15. The Koan of the Deadlock
Two monks wrote a concurrent app.
Each took a mutex and waited for the other.
The CPU idled.
The app was stuck.
"Why is it not crashing?" asked one.
"Because this is peace," said the other.
Lesson: Not all stillness is serenity. Sometimes it is deadlock.
16. The Koan of Time()
"My code checks time()
and loops until it changes."
"And if the system clock jumps backward?"
The student stared.
"What is time, really?"
The master set the system clock to 1970.
The loop never exited.
Lesson: Time is not monotonic. Nor is progress.
That's Part II.
Part III will go deeper still: signals, exec(), zombie processes, TTY madness, and the illusion of state.
Let me know if you want to shape it.