this post was submitted on 02 Feb 2024
675 points (97.7% liked)

Programmer Humor

32032 readers
1344 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
675
submitted 7 months ago* (last edited 7 months ago) by Kaelygon to c/[email protected]
 

edit: fixed thumbnail

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 7 months ago (3 children)
[–] [email protected] 5 points 7 months ago

Try turning it off and on again

[–] okamiueru 3 points 7 months ago

Processes can make their own processes. If you know of such a secondary process, you might still want to terminate the one at the top.

Something like that?

[–] [email protected] 2 points 7 months ago* (last edited 7 months ago)

Processes in most operating systems (I'll use Linux, because it's what I know and because...Lemmy) are organized in a tree like structure. There's some initial very low level code used to start the OS, and every other process spawns from that, which is to say they tell the operating system "Hey, please make this process I'm gonna tell you about - allocate resources for it, etc." The operating system creates it and binds that new child process to the first one. The process that spawned the other process is called its parent. The process that just got spawned is called a child. You could also call them root and leaf processes, I suppose, but nobody really does that. Sometimes you want to get rid of all the child processes a process spawns, but leave the running process intact. Sometimes you want to kill the process that spawned everything and also cleanup anything it might have created. There are lots of programming scenarios in which you might want to do either. It really depends on how your application is designed and what it's doing.

That all said, there's a command in Linux called "kill" and you can tell it the process id, process group id, etc. to kill a process or a process group. You can also manipulate what are called SIGNALS. Signals are a whole thing in Linux. They're basically small values you can send to processes at any time and the operating system forces the process to perform some action whenever it receives one of them. SIGTERM basically stands for "SIGNAL: TERMINATE PROCESS." So if you "trap" the SIGTERM, you can basically tell the operating system - whenever this parent process receives a SIGTERM, ignore it. The other processes in the process group - the child processes - all terminate, though, when they receive it.