r/C_Programming • u/Admirable_Studio8266 • Jun 07 '26
Discussion Fix patches without resetting the instance?
Can anyone guide me through how a program would work to where you can fix some bugs without restarting the program? Not DLLs, just one big loop. Would I be reading input and parsing it? Am I just making an interpreter for anything I want to run? Obviously you can't patch anything, but maybe I want to change the byte order for a socket packet or something. Without actually stopping the server.
7
Upvotes
11
u/ByMeno Jun 07 '26
What you’re describing is usually called runtime configurability or hot-reload behavior. In practice, you don’t “patch” a running binary in C without mechanisms like DLLs/plugins or restarting.
If you don’t want plugins, the common approach is designing your program to be data-driven: you keep a main loop running, and you change behavior via config files, commands, or an embedded scripting system.
So yes, if you want arbitrary behavior changes at runtime (like packet processing rules), you’re basically moving toward a small interpreter or scripting layer inside your program, rather than patching compiled code.
1
u/RRumpleTeazzer Jun 07 '26
you need to replace the code that is run
1
u/RainbowCrane Jun 07 '26
In a modern Internet application you would likely handle this via load balancing and rolling restarts. While there are still applications that maintain 24/7/365 uptime for a single process that’s pretty rare.
What is your use case that requires your process never to go down?
2
u/vertigosol Jun 07 '26
I mean in theory you could write a whole new program and move all the referenced addresses of runtime registers like SP and PC to swap over. You wouldn't really augment a server in real-time like you are indicating. Byte orders are normally fixed on the network or architecture
2
u/KindaAwareOfNothing Jun 07 '26
irrc someone made a tool like this for game dev. Can't remember it's name now.
But you might want to take a look at debuggers (gdb for example)
3
u/u8589869056 Jun 08 '26
I did it once, for the hell of it. I applied a patch without rebooting. The patch from Berkeley changed a > to a >= in one line. The system was a Vax/780 used by a university department. First, I changed the source file. Then I used the debugger to change the .o file without recompiling. Then I used another debugger to patch the executable without relinking. Finally, in that same debugger, I changed the code in memory.
The program? vmunix.
1
u/timonix Jun 08 '26
Sounds like you are looking for Erlang
1
u/vaibhav92 Jun 09 '26
On linux you can use libpulp which can be used to livepatch a running process instance . Dont think its widely used atm. SUSE had given a demo of this some time back https://www.youtube.com/watch?v=EfhE15zh8Sc
Git repo: https://github.com/SUSE/libpulp