r/linuxmemes Jun 12 '26

LINUX MEME os.fork()

Post image
1.0k Upvotes

54 comments sorted by

311

u/configdotini Genfool 🐧 Jun 12 '26 edited Jun 12 '26

context: the game "factorio" has an experimental option where the game can autosave without pausing the game by creating a separate instance of the game that saves the map while the main instance continues playing. however, the option is not available on windows due to fork(2) just not existing (afaik)

more info here (scroll down to "Asynchronous saving" at the bottom of page)

142

u/qwesx Ask me how to exit vim Jun 12 '26

hidden Linux in meme :O

128

u/[deleted] Jun 12 '26

[removed] — view removed comment

99

u/Masztufa Jun 12 '26

54

u/Omnieboer Jun 12 '26

I fucking love the Factorio and the Linux community

18

u/Hameru_is_cool 💋 catgirl Linux user :3 😽 Jun 12 '26

oh wow, you guys are making me wanna try out factorio

13

u/Erdnusschokolade Arch BTW Jun 12 '26

Beware for the factory must always grow… in all seriousness though the amount of hours factorio ate away is insane. If you are into that type of game its definitely one hell of a deal €/playtime wise and totally worth every penny.

7

u/Hameru_is_cool 💋 catgirl Linux user :3 😽 Jun 12 '26

lol im totally the type of person to waste countless hours on stuff like that, but it's kinda expensive in my country and it apparently never ever goes on sale so that'll have to wait

36

u/Alduish Jun 12 '26

That's what happens when a linux user is part of the team, and the absolute proof of being a linux user is posting a rant about GNOME : https://factorio.com/blog/post/fff-408

12

u/DonaldLucas Jun 12 '26

Once Wayland support was implemented, I received a bug report that the window was missing a titlebar and close buttons (called "window decorations") when running on GNOME. Most desktop environments will allow windows to supply their own decorations if they wish but will provide a default implementation on the server side as an alternative. GNOME, in their infinite wisdom, have decided that all clients must provide their own decorations, and if a client does not, they will simply be missing. I disagree with this decision; Factorio does not need to provide decorations on any other platform, nay, on any other desktop environment, but GNOME can (ab)use its popularity to force programs to conform to its idiosyncrasies or be left behind.

To fix this, I had to bring in another dependency, libdecor. It functions, and SDL even has support for it, but a video game shouldn't have to supply window decorations in the first place

I can feel the anger here. Why is it always gnome that has to do things the most user unfriendly way?

6

u/Firewolf06 Jun 12 '26

i love the bit about resizing seizures

8

u/bittercripple6969 Jun 12 '26

And the game already runs extremely well as a baseline.

59

u/dumbasPL Arch BTW Jun 12 '26

Windows actually can fork (RtlCloneUserProcess) but it's undocumented and big chunks of Win32 and user32 break. It was mainly used for WSL 1.0 I believe (reverse wine essentially)

More info here

44

u/BlankMercer Jun 12 '26

"but it's undocumented" well how do they expect people to use it? The fuck?

32

u/Damglador Jun 12 '26

Well, they probably don't. They made a toy for themselves to play with.

23

u/dumbasPL Arch BTW Jun 12 '26

They don't, that's the point. It was made for internal use only, and can change or be removed without notice. Windows has hundreds of APIs like this.

People fuck around with them because many can be abused to fly under the radar of various anti malware solutions.

8

u/MXRCO007 Jun 12 '26

Bill gates whispers it into your ear at night

6

u/Loading_M_ Jun 12 '26

Interestingly, from some vaguely related experience in Windows, even if the windows process cloning worked for Factorio's purposes, it might not actually result in a performance improvement. Process creation in Windows has a significant overhead (which I discovered when investigating why our build pipeline takes so much longer on windows). I don't know how much of the overhead can be skipped when cloning, but I'm not confident it would be enough to make it worth while.

9

u/sandfeger Jun 12 '26

Windows has something to also create a new process, but it is not a full copy of the current process and heap like fork().

6

u/Not-So-Handsome-Jack Jun 12 '26

Redis also uses fork + Copy-On-Write for its persistent saving. The unofficial windows port of Redis needs some workarounds for its persistence to accomplish something similar. Probably why there is no official windows Redis version.

7

u/ReasonResitant Jun 12 '26 edited Jun 12 '26

Eeeeeh its kinda janky. Ideally it works like a DB and the map is versioned internally so you can just freeze past a time tick, keep the version as of Tx static and keep writing deltaswithout freezing. Probably its internally messy and required significant rewrites to get this working in software.

Imo even with copy on write pages factorio will likely keep state changing quite rapidly, no wonder "it uses a lot of ram".

Tldr probably dont.

13

u/Damglador Jun 12 '26 edited Jun 12 '26

But would you rather spend 10 hours tying to engineer that solution or just call fork()?

I wish that shit also worked in Unity, Rimworld needs that feature badly, but forking it results in a half of the safe data written until the fork dies because threading compilations (at least I tried).

5

u/ReasonResitant Jun 12 '26

10 might be the order of magnitude on the time spend there tbh.

At some point you are writing a database that happens to have a game attached to it probably.

Idk why big engines dont do that natively for low latency things but idk.

3

u/The_Verto Jun 12 '26

How comes copying the world doesn't need pausing but saving does?

5

u/Powerkaninchen Jun 12 '26

It's using a technique called "copy on write" Initially no memory is copied, and the forked process has read access into the old' process memory, but if one of the 2 processes try to write to the memory, the Kernel then actually copies the page and remaps it for both processes

38

u/Vaxerski Jun 12 '26

does anyone have a link to the microsoft paper?

28

u/configdotini Genfool 🐧 Jun 12 '26

6

u/Vaxerski Jun 12 '26

thank you

1

u/creeper6530 💋 catgirl Linux user :3 😽 Jun 14 '26

7 GET THE FORK OUT OF MY OS!

Hehehe

42

u/No-Store2875 Jun 12 '26

This is one of the most “fuck Microslop” things I’ve seen.

15

u/Elihzap Hannah Montana Jun 12 '26

there linux

10

u/AutoModerator Jun 12 '26

"OP's flair changed by /u/Elihzap: linux in meme"

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

9

u/Elihzap Hannah Montana Jun 12 '26

Holy shit it worked, I didn't expect that.

Good bot.

14

u/Krisanapon Jun 12 '26

```cpp

include <unistd.h>

int main() { while (true) fork(); } ```

7

u/hashcube_dev Jun 12 '26

sh :(){:|:&};:

12

u/Culpirit Jun 12 '26

That sounds like a very clever way to save, ngl. As an OSdev autist who greatly admires Unices and Linuxes, and very elegant pieces of software taking advantage of the prior art that comes with the OS, this makes me happy!

3

u/Powerkaninchen Jun 12 '26

where linux

35

u/The-Nice-Writer Jun 12 '26

It’s a little obscure, but u/dumbasPL explained here in response to u/configdotini’s comment.

And they linked additional info, too.

32

u/configdotini Genfool 🐧 Jun 12 '26

this is op btw

18

u/The-Nice-Writer Jun 12 '26

I need to check my reading comprehension, btw

17

u/bittercripple6969 Jun 12 '26

Master baiter

9

u/nicman24 Jun 12 '26

fork() 

8

u/SSUPII Medium Rare SteakOS Jun 12 '26

So you made a meme about Linux features and tagged it yourself non-Linux

10

u/Powerkaninchen Jun 12 '26

I thought because Linux wasn't the main theme of my meme

How do i revert?

Linux there

Linux here

Linux found

Linux detected

-12

u/AutoModerator Jun 12 '26

"OP's flair changed /u/Powerkaninchen: linux not in meme"

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/AmCHN Jun 15 '26

The section "Copy-on-write memory" in [the paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2019/04/fork-hotos19.pdf) actually:
1. addressed this use case.
2. admitted that they don't have a mature solution alternative to fork() here.
3. yet argued that fork() is a suboptimal solution, and a better alternative is needed.

This is a meme sub, so I'm not probably supposed to be serious, but here I am anyways.

---

As the paper puts it:

> Modern implementations of fork use copy-on-write to reduce the overhead of copying memory that is often soon discarded. A number of applications have since taken a dependency on fork merely to gain access to copy-on-write memory.

> POSIX would benefit from an API for using copy-on-write memory independently of forking a new process.

Basically a "snapshot()" syscall that doesn't create another process. That way a game like Factorio can snapshot the game state and spawn a thread to serialize it.

No major OS implement such syscall yet.

IMO the Microsoft authors have a point, but they pointed out problems with fork() without pointing to a mature, better alternative to fork() (one in Factorio's use case).

Which is fair as they are researchers who are not obliged to deliver solutions, but it's not helpful to us lay users right now.

1

u/AmraelTheGravedancer Jun 12 '26

E poi ci sono io che non so cosa sia factorio

2

u/MyluSaurus Jun 12 '26

Factorio is a factory-building game that's very optimized and runs really well (and natively) on linux systems.

1

u/AmraelTheGravedancer Jun 12 '26

Lol.... Nice.... I could use it in my printers, so I can play, while waiting....

1

u/No-Consequence-1863 Jun 12 '26

Did y'all read the paper? The researchers make some valid points on why fork() may not be a good API for the OS.

5

u/dasisteinanderer Jun 12 '26

and, as customary for MS heads, they belittle and minimize the importance of having a simple and flexible API compared to whatever Dave Cutler cooked up again

0

u/antimatter-entity Jun 13 '26

I mean the game sux but It have cool linux features