This is Episode 2 of The Vibe Coder’s Guide to the Machine: computer science for a new generation.
You asked an assistant for a bot that checks a product page every ten minutes and sends a Telegram message if the price of some headphones drops. You got a short file called price_bot.py. You ran it on Monday, ran it again in a new tab on Tuesday because it had gone so quiet, and on Wednesday the assistant ran it from its own terminal to check that it worked. On Thursday the price dropped and your phone buzzed three times with the same message. One file had become three processes. A process is the program running: it has its own memory, holding values such as the last price it saw, and its own place in the work. Picture each process as a house with its own kitchen, with a wall the operating system keeps between the houses, so by default no process can simply read or write another’s memory, and getting through the wall takes an arrangement the system allows. The three processes were three houses, each checking the page, and each quite sure it was the only one. Inside each, the assistant had also started a listener thread, a second line of work that shares the kitchen and answers the message /price with the latest price.
The guard that would not leave
After Thursday you ask the assistant for a guard against second copies. It adds a few lines that run just after the listener thread starts: the bot creates a file called price_bot.lock, and refuses to carry on if that file already exists. Then it tests the guard in a scratch folder, with copies of the bot that have it, separate from the week’s three processes, which never ran the guard. It starts one copy, which creates the lock file, then a second, and reports back that the second copy was refused with Python’s error for a file that is already there, FileExistsError: [Errno 17] File exists: 'price_bot.lock', so the guard works.
To be sure, you look at the list of running processes, which you can see in Activity Monitor on a Mac, Task Manager on Windows, or with ps, a command that lists processes, in a terminal. The error is real, and the second copy did fail at once, but its prompt, the line where you type your next command, never came back. Two seconds after the failure, the listing shows two Python processes with the same command. One of them is the refused copy, still running.
When a Python program’s main line of work ends, as it did here with the error, Python checks whether any helper thread it must wait for is still running, and if one is, it keeps the process alive until that thread finishes. The listener had started before the error and never finishes, so the refused copy stays. A helper thread can be marked as one the program does not wait for, and then it is simply dropped at exit. Had the listener been marked that way, the failed copy would have exited at once and only the first would remain. The guard worked; the process it refused simply declined to leave.
You end the scratch copies with Ctrl-C or kill, pressing Ctrl-C twice for the first copy, since one press only leaves it as stuck as the refused copy, and no process from the scratch folder is left running.
What “stop” stops
The refused copy outlived its own error because of a thread, and stopping a process is where the difference between threads and processes decides what actually ends.
The normal way to stop a program you started in a terminal is Ctrl-C, pressed in the terminal where it runs. The terminal sends an interrupt to its foreground group: the processes started together from that terminal, which all receive whatever the terminal sends. It is a polite request to finish, and usually the program does and the prompt comes back. The pattern worth knowing is what happens when the finishing is itself waiting on something: the first press asks the program to wrap up, and if the wrap-up is waiting, as Monday’s process will be on its listener thread, the second press means stop waiting. Docker Compose says this out loud, printing “Gracefully stopping... (press Ctrl+C again to force)” on the first press; it is the same idea. In Python, though, the second press is not a force-kill. It only interrupts the wait, and kill -9, below, is the next step up. On a Mac or Linux, closing the tab or window ends it too, because the terminal sends a signal called SIGHUP, short for “hang up”, telling the program nobody is there any more, and by default the program then ends. Some programs are written to ignore it. On Mac or Linux, kill and a process ID ask that process to stop. A stop request like this, sent by the operating system to a process, is called a signal, and the one a plain kill sends is a signal the program may handle, for example by tidying up before it ends, or may ignore. kill -9 does not ask. It sends a signal the program is never shown, and the operating system ends the process at once. The program cannot handle that signal, ignore it or run any code of its own, so it cannot tidy up, and work it was in the middle of may be left behind, such as a half-written file or a half-sent message.
End a process and every thread inside it ends with it: the main thread, the listener, the lot, in one go. The threads have nowhere else to exist, because the memory they were running in is gone. Python gives you no way to kill a single thread from outside; a thread ends when it reaches the end of its own code or when its process ends. Stop one of the three processes, on the other hand, and the other two carry on checking the page as if no change had happened, because as far as they can tell none has. Whether “stop it” stops the whole bot depends on whether “it” is a thread or a process.
On Friday you decide the bot has done its job. In Monday’s tab, the one in front of you, you press Ctrl-C. A short error report, a traceback of five lines or so ending in KeyboardInterrupt, appears, and then nothing: no prompt, the same stuck state as the refused copy. That is the first press doing what it asks. The main thread has left the loop to wrap up, and the wrap-up is waiting for a listener that never finishes. You press Ctrl-C a second time, which means stop waiting. Another traceback appears, ending in KeyboardInterrupt again, and below it the prompt returns: the press interrupted the main thread’s wait for the listener, the process ended, and the listener ended with it. Monday’s process is gone. You find Tuesday’s tab and close it, and the hang-up signal ends Tuesday’s process, listener and all.
On Saturday the price drops again and your phone buzzes once, because one process is left: Monday’s ended with the second Ctrl-C and Tuesday’s with its closed tab, but Wednesday’s is still checking. That message comes from Wednesday’s process, the one the assistant started from its own terminal, in no tab you have ever seen. The only place to find it is a process list or Activity Monitor, where it sits under the name Python, still quite sure it is the only one.
A process that starts other processes
The shop builds its price with JavaScript after the page loads, so fetching the page’s raw text was not enough, and the assistant reached for Playwright, a library that drives a real web browser with no window. Playwright does not run the browser inside the bot’s process. It starts a driver of its own, a process running Node, the program that runs JavaScript outside a browser, and the driver starts Chromium as a separate process, which the library talks to over a connection. A two-sentence request about headphones is now running a web browser that has no window and no one to look at it.
That browser is a child process: a process started by another process, which becomes its parent. A child is not a thread. It has its own memory, its own process ID and its own lifetime, and by default the parent can no more simply read or write its memory than the three bot processes could each other’s, unless the two set up an arrangement the system allows. To keep the house picture, a child is a second house built next door. Its kitchen is its own, and the two households talk over the fence, by passing messages across the boundary.
When the bot shuts down normally, Playwright closes the browser on its way out. Kill the bot outright with kill -9 and it gets no chance to close the browser, yet within a third of a second the driver, Chromium and its helpers are gone as well, though the bot never got to ask them to go. What held them is a connection. The driver is tied to the bot by one, and Chromium is tied to the driver by a pipe, a live connection between two processes. Kill the driver alone and the browser vanishes just as fast: its parent ended, and it went too.
A child with no such tie behaves differently. Have Python start a second Python process that only sleeps, kill the parent the same way, and the child keeps running. On a Mac, a process whose parent has died is handed to process 1, the system’s first process, which is launchd. The operating system has a formal procedure for orphans, it works smoothly, and launchd keeps the child, sleeping on with nobody left to answer to. A child can also be deliberately started in a new session of its own, detached, meaning cut loose from the session, the group of processes tied to one terminal, so it keeps running after the terminal is gone. Such a child is not in the terminal’s group at all, and Ctrl-C there never reaches it. So the useful question about any child is not who started it, but whether any tie binds its life to its parent.
Each process is started, runs and ends on its own terms. What a process held, the system takes back when it exits; what it started may outlive it. So when you stop a process, ask what it started, and whether that will stop too.
What the process holds while the clock runs
Look at what one of the three processes is holding at any moment. The current value of last_price. Its connection to Telegram. Its place in the loop, which might be halfway through a ten-minute sleep. The browser it started. Together these are its state: all that is true of the process right now, which the next step depends on. The file starts last_price at nothing, written last_price = None. The process says 249.00. Only one of them knows what the price was ten minutes ago. Two processes made from the same file, started a day apart, have different states, which is why “it works on my run” and “it fails on yours” can both be true of the same code.
Memory is where the process keeps its state while it runs: the region of the computer’s working memory the operating system handed it at the start and lets it grow. Memory belongs to the process. When the process exits, the system takes that memory back and the state goes with it. Restart the bot and the new process begins with last_price set to None; all the old one knew is gone, quietly and completely. That is also why restarting so often makes a problem disappear for a while. A restart is not a repair. It is a fresh process with an empty memory and no record of how the old one got into trouble. What the old process did to the world does not go back. The messages it sent stay sent.
Then there is time, which a process spends in two quite different ways. Each check takes a moment of real work: fetch the page, find the price, compare. Then time.sleep(600), and for ten minutes the checking thread sleeps and does no work, while the listener thread can still run. Leave one of these processes running for a week and it will have existed for 168 hours while spending a small fraction of that actually executing instructions. In a terminal, ps -o pid,etime,time -p followed by a process ID lists that one process with both clocks: ELAPSED, how long the process has been alive, and TIME, how long it has spent being worked on. A process can be alive for days and busy for minutes.
Waiting is still running, though. A sleeping process holds its memory, its connection, its child browser and its place in the loop, and the world does not wait with it. The page can change while it sleeps, a login can expire, the price can rise and fall again between two checks. Being alive, doing work and still being in step with the world are three different conditions.
A boundary someone chose
The wall between the three processes was a decision, and so is the way they take turns on one processor, a separate choice whose early answer was for programs to share the processor by agreement. The classic Mac OS, from System 7.0 and with MultiFinder before it, let an application give up the processor only at certain calls, and Apple’s documentation explained the name: “Because the smooth operation of all applications depends on their cooperation, this environment is known as a cooperative multitasking environment.” Microsoft’s notes said Windows 3.x could run several applications at once “as long as all of the programs are well behaved”. What cooperation bought was that a program was switched out only at calls it made itself, never at a moment it did not choose. It assumed every program would behave, and the burden of behaving fell on the developer, who had to break the work into small pieces and keep yielding. If one program did not yield, the user could not switch to another.
Windows 95 and Windows NT used preemptive multitasking instead: the operating system can take the processor from a program at any time and give it back later “without your knowledge or permission”. That lifted the burden of yielding from the developer and gave up the guarantee that a program is switched out only at its own calls: a program can now be paused at moments it did not choose, so two threads sharing one value must allow for catching each other halfway. Preemption assumes no program can be trusted to hand the processor back. The bot’s three processes live inside both answers, each sure it is alone, because the system has gone to some trouble to make that true.
The process is what you answer for
On 27 July 2012, Knight Capital, then one of the largest traders in US stocks, began rolling out new trading code to the eight servers that ran one of its order-routing systems. According to the US Securities and Exchange Commission’s later account, a technician copied the new code to seven of them. The eighth still held old code that had not been used in years, and on 1 August 2012 a switch the new release reused, which the old code also read and took to mean something else, turned that old code back on. In about 45 minutes it sent millions of orders into the market, and the firm lost more than $460 million. The program in Knight’s release was the one they meant. What ran was eight servers, separate computers each running processes of its own, and on one of them those processes were executing a different program entirely.
You bot will probably never move $460 million in 45 minutes, but the shape is the same at every size. What you meant, what was written and what is actually running can each differ from the others, and only the last one touches the world. Building with an assistant widens the distance between them. The assistant writes the program, and often it starts processes too, from its own terminal, to check its work. The conversation ends. The processes do not. Wednesday’s run, started only to confirm that the bot worked, was still checking on Saturday. Along the way the assistant makes decisions that are not in your prompt: a listener thread here, a child browser there. Each of those decides what the process holds, how long it lives and what stopping it actually stops. They are not only implementation. They are choices about the process, made quietly on your behalf.
Answering for the process does not require reading every line of code. It requires a few questions that work on any software, including software you will never read, and including the assistant’s own. How many of this are running right now? What does each one hold? What does it reach out and touch? When I stop it, what ends with it, and what keeps going? The operating system answers the first three; the fourth takes watching, or knowing what ties the parts together. Activity Monitor and ps are not tools reserved for programmers. They are how you look at the process instead of the description.
The fix for Thursday’s three messages was never in the file. The file was right all along. The fix is knowing there were three processes, that each of them was yours from the moment it started, and that one of them is still listed under the name Python, sleeping through its ten minutes, waiting for the next drop.
The Vibe Coder’s Guide to the Machine. You can build it. Now understand it.




