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

Support for posix-spawn? #510

Open
NARKOZ opened this issue Jul 29, 2020 · 2 comments
Open

Support for posix-spawn? #510

NARKOZ opened this issue Jul 29, 2020 · 2 comments

Comments

@NARKOZ
Copy link

NARKOZ commented Jul 29, 2020

Would it be possible to use posix-spawn for shell commands?

It's more efficient than popen3 and provides meaningful process hierarchies because it performs a single fork/exec. (popen3 double forks to avoid needing to collect the exit status and also calls Process::detach which creates a Ruby Thread!!!!).

It handles all max pipe buffer (PIPE_BUF) hang cases when reading and writing semi-large amounts of data. This is non-trivial to implement correctly and must be accounted for with popen3, spawn, or hand rolled fork/exec code.

It's more portable than hand rolled pipe, fork, exec code because fork(2) and exec aren't available on all platforms. In those cases, POSIX::Spawn::Child falls back to using whatever janky substitutes the platform provides.

@markevans
Copy link
Owner

Hi - looks interesting, though I'd be reluctant to because I want to keep dependencies to a minimum.
Was there a specific case where it made a big difference or where popen3 was being problematic? I don't mind popen3 being slightly less efficient if it's not the bottleneck

@NARKOZ
Copy link
Author

NARKOZ commented Jul 29, 2020

Another popular image processing library - minimagick, has a plug-in support for it, the dependency being optional. Difference can be huge when dealing with thousands of images.

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

No branches or pull requests

2 participants