Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spawn() family of calls #637

Open
erkinalp opened this issue Jul 1, 2018 · 11 comments
Open

spawn() family of calls #637

erkinalp opened this issue Jul 1, 2018 · 11 comments
Labels
enhancement Feature request

Comments

@erkinalp
Copy link
Contributor

erkinalp commented Jul 1, 2018

spawnve which does not call fork and execve under the hood will prevent unneeded copies.

@EtchedPixels
Copy link
Owner

Except that we have pretty much nothing that could use it. I think vfork() would be a better option and that is on my longer term list. The posix_spawn functions can then be written to use vfork().

I'd happily take an implementation for libc of posix_spawn* that used fork() for now so we have it ready for vfork() in future and people can use it.

@EtchedPixels EtchedPixels added the enhancement Feature request label Jul 1, 2018
@erkinalp
Copy link
Contributor Author

erkinalp commented Jul 1, 2018

The problem is we do not have COW pages on Z80 and 6502, each fork is a complete time-consuming copy of previous process. spawnve could be implemented as a new process handle + empty memory block.
The default shell could be modified to use spawn instead of fork for background (ampersand) process invocation, saving time.
It will not work for foreground incovation because of terminal semantics.

@EtchedPixels
Copy link
Owner

Once we get a vfork() it won't copy. See the documentation for vfork on classic unix

@erkinalp
Copy link
Contributor Author

A bit late, but would this be level 1, 2 or 3?

@EtchedPixels
Copy link
Owner

It's kind of irrelevant at this point as there is no use case and nobody needs it or has bothered to provide an implementation in the past 5 years nor anything that needs it.

The 8bit ports can't support it for various architectural reasons, the 68K copies only a few Kb and fast so it's mostly a non-issue and the ESP8266 and modern small risc chips fork /bin/sh in almost no time as it's a mere 32K which for a modern fast risc chip doesn't take any time

@bscottm
Copy link

bscottm commented Aug 1, 2023

@erkinalp: vfork() was a Berkeley-ism because older Unixen did a full process copy in fork(). Given that fork() and vfork() were (and are) followed by an immediate exec(), vfork() made sense. Then someone discovered demand paging (again) and the need for vfork() disappeared.

@erkinalp
Copy link
Contributor Author

erkinalp commented Aug 2, 2023

@bscottm Yes, but the need for spawn() did not. There is a reason POSIX now has a posix_spawn() call.

@bscottm
Copy link

bscottm commented Aug 2, 2023

@erkinalp: Didn't say anything about spawn() [courtesy of Microsoft]. All spawn() does is package fork() and exec().

@erkinalp
Copy link
Contributor Author

erkinalp commented Aug 2, 2023

No, what I mean is definitely a posix_spawn() that does not fork under the hood, but rather create a fresh process descriptor in a manner similar to Windows NT's CreateProcess() and then exec() to it.

@bscottm
Copy link

bscottm commented Aug 3, 2023

@erkinalp: fork() is supposed to create a fresh process descriptor. Copy-on-write and demand paging make fork() more efficient, when possible. Neither 6502 and Z80 have memory management units, so copy-on-write isn't feasible. Whether spawn and its variants exec() depends on the return value from fork(). That doesn't preclude an implementation from optimizing, as it sounds like is happening in this case.

@EtchedPixels
Copy link
Owner

To be more accurate programs then got enormously bloated and vfork became relevant again.

In the Fuzix case the only cases vfork looks useful are flat systems like 68K as it avoids a data copy on fork and switch, but nothing we have that forks copies much data (riscv and ns32k are a bit worse as the toolchains don't generate split code/data relocatable binaries- but riscv is fast and ns32k is more a tool chain problem)

So no use case, and no use case means not used means buggy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request
Projects
None yet
Development

No branches or pull requests

3 participants