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

Add Deno.kill(pid, signo) and process.kill(signo) (Unix only) #2177

Merged
merged 4 commits into from
Apr 22, 2019

Conversation

kevinkassimo
Copy link
Contributor

@kevinkassimo kevinkassimo commented Apr 21, 2019

Implemented for Unix only first.

Also add a test to verify if process gets killed on close is working fine. If it works, then we might want to close #1494

@kevinkassimo kevinkassimo changed the title Add Deno.kill(pid, signo) and process.kill(signo) Add Deno.kill(pid, signo) and process.kill(signo) (Unix only) Apr 21, 2019
const inner = msg.Kill.createKill(builder, pid, signo);
dispatch.sendSync(builder, msg.Any.Kill, inner);
}

export class Process {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this commit, but I think we should rename this to Subprocess.

js/process.ts Outdated
export enum Signal {
SIGHUP = 1,
SIGINT,
SIGQUIT,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it's equivalent, I would prefer explicitly assigning values to each of these. It just makes things a bit more obvious if it ever needs to be debugged.

SIGINT = 2,
SIGQUIT = 3,
/* .. */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I've just realized that certain signal numbers are platform dependent (like 10 is SIGBUS on macOS but SIGUSR1 on Linux). I might also need to check the current platform to decide which set of signals to export.

Copy link
Member

@ry ry Apr 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah too bad. I thought maybe posix defined those - apparently not.
I think there's two options:

  1. Do something similar to Deno.platform where we generate the typescript during build.
  2. Pass the signals as strings ("SIGINT") and map them to their platform dependent integers outside of V8. This is what we did in Node IIRC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently resorting to

export const Signal = platform.os === "mac" ? MacOSSignal : LinuxSignal;

Using string names also not quite ideal unless we build a similar mapping on the Rust side, since from_str in nix crate assumes mostly linux signal name mappings

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that works

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - cleanly done

@ry ry merged commit 1d4b92a into denoland:master Apr 22, 2019
@kevinkassimo kevinkassimo deleted the process/kill branch December 27, 2019 07:53
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 this pull request may close these issues.

Function to kill a running process
2 participants