Skip to content

[v2] terminal cancellation on async_execute() results in exit status 0 instead of 9 #503

@pgit

Description

@pgit

When calling terminate on a V2 process, the exit code on async_wait() is 0, but should be 9 (SIGKILL).

#include <boost/asio.hpp>
#include <boost/process/v2/process.hpp>
#include <iostream>

int main()
{
   boost::asio::io_context context;
   boost::process::v2::process child(context, "/usr/bin/sleep", {"10"});
   child.async_wait([](boost::system::error_code ec, int status){
      std::cout << status << std::endl;
   });
   child.terminate();  // prints 0 -- should be 9 (SIGKILL)
   // child.interrupt();  // prints 2 (SIGINT)
   // child.request_exit();  // prints 15 (SIGTERM)
   context.run();
}

This seems to be due to the implementation of terminate(), which -- unlike interrupt() and request_exit -- also calls wait:

That wait() correctly retireves exit status 9, but before async_execute() completes, ::waitpid() is invoked again somewhere. If the wait() is removed, termiante() behaves correctly -- but I do not know if that has other implications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions