Skip to content

Create a tokio::process::Child in a new process group #4312

Closed
@kpcyrd

Description

@kpcyrd

Is your feature request related to a problem? Please describe.

I want to create a child process and later be able to kill this child with all of it's sub- and sub-sub- children on unix-style operating systems.

Describe the solution you'd like

Something along the lines of:

.set_process_group(0)

Describe alternatives you've considered

I'm currently using this code to implement it:

    unsafe {
        cmd.pre_exec(|| {
            // create a new process group
            let pid = nix::unistd::getpid();
            if let Err(err) = nix::unistd::setpgid(pid, Pid::from_raw(0)) {
                warn!("Failed to create new process group: {:#?}", err);
            }
            Ok(())
        });
    }

setpgid needs to be called before exec is called after fork.

Additional context

https://www.gnu.org/software/libc/manual/html_node/Process-Group-Functions.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-feature-requestCategory: A feature request.M-processModule: tokio/process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions