The Critical Pause: What Happens When You Press "Stop\Stop"
The Critical Pause: What Happens When You Press "Stop"
Eventually, every node must come to an end. Whether you are restarting your computer or just finished for the day, you will eventually tell the node to stop. In most programs, you just click the "X" and they disappear. But in Bitcoin, this is a Critical Operation. If you stop at the wrong moment, you could leave the database in a "Half-Finished" state, which could lead to corruption and the loss of your transaction history. It is the "Graceful Exit" of the software. It is the "Sunset." It is the "Closure." It is the "Twilight." It is the "Pause." It is the "Respect." It is the "Order." It is the "Finality." It is the "Solemnity of the End." It is the "Grace of the Goodbye."
The Signal Interrupt
When you press Ctrl+C or send a "Stop" command from your terminal, the Operating System sends a "Signal" to the node. The node has a special "Listener" that is waiting for this exact signal. It is a "Message from the Outside World" that tells the node its time is up. It is the "Bell of the Evening." It is the "Call." It is the "Summons." It is the "Invitation to Rest." It is the "Angel of Death." It is the "Trumpet of the End." It is the "Clarion Call to Sleep."
In src/util/signalinterrupt.cpp, the node catches the signal:
/**
* Handles the signal sent by the user to stop the program.
* It doesn't stop instantly; it turns on the "Exit" sign.
*/
static void HandleSIGTERM(int)
{
// Turning on the Red Exit Sign.
// This variable is watched by every thread in the program.
g_shutdown = true;
}
Explaining the Code: The Order to Retreat
-
HandleSIGTERM: This is a tiny function with a massive responsibility. It is one of the few things in the program that is allowed to "Interrupt" everything else. When it runs, it doesn't stop the program; it just flips a switch. It is the "Gentle Tap" on the shoulder of the program, letting it know that the day is over. It is the "Call to the End." It is the "Bells." It is the "Command." It is the "Signal." It is the "Tap." It is the "Whisper." It is the "Injunction." It is the "Summons." It is the "Quiet Order." It is the "Soft Landing." -
g_shutdown = true: This is a "Global Variable"—a piece of information that every worker in the factory can see. It’s like a giant red light flashing on the wall. The workers don't drop their tools instantly; instead, they see the light and think: "Okay, I need to finish this last task and then head for the door." It is the "Unanimous Decision" to stop working. It is the "Shared Knowledge." It is the "End." It is the "Cease-fire." It is the "Sign." It is the "Light." It is the "Will." It is the "Resolution." It is the "Consensus of the End." It is the "Flash of the Finality."
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: