Skip to content

Process should support the child outliving the parent #14467

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

Closed
alexcrichton opened this issue May 27, 2014 · 1 comment · Fixed by #14551
Closed

Process should support the child outliving the parent #14467

alexcrichton opened this issue May 27, 2014 · 1 comment · Fixed by #14551

Comments

@alexcrichton
Copy link
Member

Current, Process invokes wait in its destructor to prevent leaking the child process for a long-running parent (see #13854 for discussion and more info). This does not support the use case of a child outliving the parent (such as creating a daemon).

A new method should be added to the Process type, perhaps detach, which consumes the Process and cancels the call to wait in the destructor. Something along the lines of:

// Forgets this process, allowing it to outlive the parent
//
// This function will forcefully prevent calling `wait()` on the child
// process in the destructor, allowing the child to outlive the 
// parent. Note that this operation can easily lead to leaking the
// resources of the child process, so care must be taken when
// invoking this method.
pub fn detach(self) { /* ... */ }
@glandium
Copy link
Contributor

There's already a detach() function on Command, which does something related but different. There might be risk for confusion if the same name is used.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jun 16, 2014
Forking off a child which survives the parent is often a useful task, and is
currently not possible because the Process type will invoke `wait()` in its
destructor in order to prevent leaking resources. This function adds a new safe
method, `forget`, which can be used to consume an instance of `Process` which
will then not call `wait` in the destructor.

This new method is clearly documented as a leak of resources, but it must be
forcibly opted in to.

Closes rust-lang#14467
bors added a commit that referenced this issue Jun 16, 2014
Forking off a child which survives the parent is often a useful task, and is
currently not possible because the Process type will invoke `wait()` in its
destructor in order to prevent leaking resources. This function adds a new safe
method, `daemonize`, which can be used to consume an instance of `Process` which
will then not call `wait` in the destructor.

This new method is clearly documented as a leak of resources, but it must be
forcibly opted in to.

Closes #14467
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

Successfully merging a pull request may close this issue.

2 participants