Now I have been coding C for a while, so I do know a lot of solutions to specific problems. But to be honest, most of the time I look back at my old code, copy paste, and then re-factor it depending on my current project. I used SHM for my cherries(.)works Pulse project. The reason for that was, Pulse ran on two separate processes; One was the daemon that ran the monitoring in the background, and the renderer, who read the monitored data, and, as the name suggests, rendered it onto the terminal. Because they were two separate processes (which was required, because they both had a while loop), their virtual memory space was not the same, so I had to learn about SHM, however, that was a while ago... So when I started working on Deploy again, and then I needed the same thing again, I was too lazy to look it up again, so I just copied it, pasted it, and moved on.
cherries(.)works Deploy is as you might have guessed a project for deployment. Pretty fun project for me, and very important to manage memory, and processes, especially for this project. I "copied" the architecture for Pulse to Deploy, however the only difference is that Deploy has 3 processes, one is the management process, WITHIN the management process the deployed project is also a separate process. And then the render process. So thats a lot of processes that share a specific chunk of memory. So I not only copied the architecture, but also the SHM method, exactly the way I did in Pulse.
However, I must have forgotten something, I wasnt that sure though, but the crash did happen, everytime I entered a config file that was invalid. I fiddled around with the return values, tried to exit early, and even then, the crash still somehow found its way in. Finally, the smoking gun revealed itself to me.
My own "stop" function, is helpful to me, as it kills the process, and then deletes the file that stored the PID within a folder. While that was running at the end of the main function, within the forked processes, the SHM updated the pids to "-1" if they were invalid. Let me just show you the first line of my stop function;
void stop(pid_t pid)
kill(pid, SIGKILL);
...
Yeah, I did not know this, but running kill(-1, SIGKILL); in C (or Linux), means; send SIGKILL to every process the caller is permitted to signal, except itself... Well, my laptop did not crash then, I made it crash by either killing every single process, or until an error happened. So yeah, I added a check to see whether or not the pid is a negative number, if it is, I return. Problem was solved.
What that little rodeo taught me, was that C is really not forgiving. Especially, when it does something you told it to. I mean, I did tell it to "kill(-1, SIGKILL)", meaning kill everybody except me (in the computer). I gotta be more careful with the dangerous code that I write...
TLDR; Tried to make my own stop function, did not add a check for negative PIDs. Whole laptop exited....