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

Process.start could have a mode that replaces current process with the started one. #41966

Open
sigurdm opened this issue May 19, 2020 · 7 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. library-io type-enhancement A request for a change that isn't a bug

Comments

@sigurdm
Copy link
Contributor

sigurdm commented May 19, 2020

Similar to exec in posix.

This would make signal handling more consistent if the spawning process is there as a script to run another program, also it might save memory.

This came up in the context of pub run (dart-lang/pub#2492) that wants to start the program in a subprocess, and let that subprocess handle signals without interference from pub run.

@sigurdm
Copy link
Contributor Author

sigurdm commented May 19, 2020

cc @jonasfj @sortie

@sortie sortie added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug labels May 19, 2020
@jonasfj
Copy link
Member

jonasfj commented May 29, 2020

See also: #42092

@mkustermann mkustermann added the area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. label Oct 29, 2020
@blopker
Copy link

blopker commented May 2, 2022

Hey all, at the risk of digging up an old issue, I wanted to share my thoughts on this. I think that allowing Dart to replace itself with another process would open up using Dart to a new class of CLI programs, specifically "process launchers". I am currently looking at different languages to reimplement asdf in since bash is not scaling well. Dart currently does not seem to have the equivalent of bash's exec $(command), which was surprising to me.

I thought using Process.start with ProcessStartMode.detached then calling exit(0) right after would work, but the detached process doesn't seem to inherit stdio. It can't print to the terminal, but it does continue to run after Dart exits. Using ProcessStartMode.inheritStdio lets the subprocess print, but only if exit(0) is not called. Dart must continue to run while the subprocess executes.

I guess I'm looking for something like ProcessStartMode.detachedInheritStdio, if that's even possible. Generally, I'm just looking for bash's exec, but in Dart. Is there a way to do this that I'm missing?

@sigurdm
Copy link
Contributor Author

sigurdm commented May 6, 2022

Perhaps exec can be called via ffi nowadays...

@blopker
Copy link

blopker commented May 7, 2022

That's an interesting idea. I haven't done any C in a while though. Do you know which exec syscall I might use?

@sigurdm
Copy link
Contributor Author

sigurdm commented May 9, 2022

I guess you can choose from one of these depending on how you want to pass the arguments: https://en.wikipedia.org/wiki/Exec_(system_call)#Unix,_POSIX,_and_other_multitasking_systems

However I'm not sure how easy it is to close file descriptors before the call:

https://stackoverflow.com/questions/56650579/why-should-i-close-all-file-descriptors-after-calling-fork-and-prior-to-callin

Someone from the VM team will know a lot more. Eg. @mkustermann

@mkustermann
Copy link
Member

Perhaps exec can be called via ffi nowadays...

Agreed - that may work (modulo #38832).

However I'm not sure how easy it is to close file descriptors before the call:

IIRC the VM open all files with O_CLOEXEC which will cause them to be automatically closed on exec(). So that may not be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. library-io type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants