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

retrieve PID of child process #132

Open
ghost opened this issue Nov 4, 2016 · 6 comments
Open

retrieve PID of child process #132

ghost opened this issue Nov 4, 2016 · 6 comments

Comments

@ghost
Copy link

ghost commented Nov 4, 2016

Shelly is missing the ability to provide the process id of a child process. This becomes essential if the child process runs amok, which happens in the real world. With the id of the feral child process in hand it can be killed with prejudice when necessary.

@gregwebs
Copy link
Owner

gregwebs commented Nov 7, 2016

Does it not suffice to kill the Shelly program? Is this for a background process?

@ghost
Copy link
Author

ghost commented Nov 7, 2016

A long running program that manages the launching, activities, and termination of executables forked into the background. All Posix shells have the ability to retrieve the process id of child processes, partly for the reason I've stated.

@gregwebs gregwebs changed the title Shelly Posix/Unix Shelly retrieve PID of child process Nov 8, 2016
@gregwebs gregwebs changed the title Shelly retrieve PID of child process retrieve PID of child process Nov 8, 2016
@gregwebs
Copy link
Owner

gregwebs commented Nov 8, 2016

I am certainly not opposed to adding this functionality, but I have always found shell scripts to be very poor vehicles for running background jobs and supervising. I did create a module that I used for the purpose of speeding up a script by running some tasks concurrently.

http://hackage.haskell.org/package/shelly-extra-0.3.0.1/docs/Shelly-Background.html

@gregwebs
Copy link
Owner

gregwebs commented Nov 8, 2016

shelly runs createProcess and gets back a ProcessHandle. However, to me it looks like the PID is intentionally not exposed. So I don't know how to actually get a PID.

@ghost
Copy link
Author

ghost commented Nov 23, 2016

These are the suspects:
System.Process.Internals
System.Process.Posix
System.Process.Common
System.Posix.Types
System.Process

createProcess :: CreateProcess -> IO (..., ProcessHandle)
data ProcessHandle = ProcessHandle !(MVar ProcessHandle__) !Bool
data ProcessHandle__ = OpenHandle PHANDLE | ClosedHandle ExitCode -- OpenHandle looks tasty
type PHANDLE = CPid -- Non Windows definition. Getting warmer!

Time to expose the System.Posix.Types.CPid.

@ghost
Copy link
Author

ghost commented Jul 24, 2017

I have code for Shelly that makes possible the exposing of the PID, et al. and much needed code for OS level job control. It involves the addition of two State record fields: a Maybe callback, and a Bool to signal the creation of fresh process groups (vital for job control and signalling). Two accessor methods setCallback and setCreateProcessGroup. Beyond that there are a handful of lines to support the functionality in Shelly.hs.

At no time is Shelly encumbered with code to actually expose the PID, just the ProcessHandle. The PID can be extracted easily by the caller's callback function and allies.

Let me know how you would like me to proceed.

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

1 participant