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

birdseye is not fully closed upon exit of birdseye #11

Closed
Almenon opened this issue Mar 31, 2018 · 6 comments
Closed

birdseye is not fully closed upon exit of birdseye #11

Almenon opened this issue Mar 31, 2018 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@Almenon
Copy link
Owner

Almenon commented Mar 31, 2018

When the user closes birdseye I close the process I started. This works.

The problem is that birdseye launches a second python process (I'm guessing the server) - I need to find some multi-platform way of closing that as well.

image

There should be some way of identifying child process - but I did not see any grandchildren of my process in the debugger.

image

Or maybe there is a way of killing a process and all of its children all at once?

@Almenon Almenon added the bug Something isn't working label Mar 31, 2018
@Almenon
Copy link
Owner Author

Almenon commented Mar 31, 2018

@Almenon
Copy link
Owner Author

Almenon commented Mar 31, 2018

Nevermind - doesn't work for windows :/

Open a process with detached on windows causes the process to pop open with a console window.
Trying to kill with a negative pid results in Error: kill ESRCH

Apparently killing all children is not supported on windows :(

nodejs/node#3617

Or at least not with node - I could spin up a subprocess to nuke them in another language.

This guy did exactly that: http://krasimirtsonev.com/blog/article/Nodejs-managing-child-processes-starting-stopping-exec-spawn

@Almenon Almenon closed this as completed in 5280cd2 Apr 1, 2018
@Almenon
Copy link
Owner Author

Almenon commented Apr 1, 2018

Confirmed fixed on windows :D

Still need to test on ubuntu

import {exec} from 'child_process'

/**
 * kills the process and all its children
 * If you are on linux process needs to be launched in detached state
 * @param pid process identifier
 * @param signal kill signal
 */
export function killAll(pid:number, signal:string|number='SIGKILL'){
    if(process.platform == "win32"){
        exec(`taskkill /PID ${pid} /T /F`, (error, stdout, stderr)=>{
            console.log("stdout: " + stdout)
            console.log("stdout: " + stderr)
            if(error){
                console.log("error: " + error.message)
            }
        })
    }
    else{
        // see https://nodejs.org/api/child_process.html#child_process_options_detached
        // If pid is less than -1, then sig is sent to every process in the process group whose ID is -pid.
        process.kill(-pid, signal)
    }
}

@Almenon Almenon added this to the v0.0.4 milestone Apr 3, 2018
@Almenon
Copy link
Owner Author

Almenon commented Apr 7, 2018

Well forgot to test on ubuntu but I just tested on mac and it looks like it works

  1. Launch birdseye

  2. ps -ax | grep python

  3. Two results

  4. Close birdseye

  5. ps -ax | grep python

  6. no results.

@alexmojaki I published a medium article on how to kill processes with node - does the explanation make sense? Any thoughts?

https://medium.com/@almenon214/killing-processes-with-node-772ffdd19aad

@alexmojaki
Copy link
Collaborator

It looks mostly fine. Some small points:

  • You mention 'Karsimiov' but the linked blog says 'Krasimir'
  • The title is not very descriptive, mention that you're killing a tree/family/group of processes
  • The comment I made in 5280cd2

@Almenon
Copy link
Owner Author

Almenon commented Apr 8, 2018

good catch. Fixed typo made in 5280cd2 and the gist. Updated the article to change the title and name.

https://medium.com/@almenon214/killing-processes-with-node-772ffdd19aad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants