Code Monkey home page Code Monkey logo

Comments (6)

alexmojaki avatar alexmojaki commented on July 28, 2024 1

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

from birdseye-vscode.

Almenon avatar Almenon commented on July 28, 2024

https://stackoverflow.com/questions/33325301/killing-a-bash-script-does-not-kill-child-processes

This looks like it might work

from birdseye-vscode.

Almenon avatar Almenon commented on July 28, 2024

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

from birdseye-vscode.

Almenon avatar Almenon commented on July 28, 2024

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)
    }
}

from birdseye-vscode.

Almenon avatar Almenon commented on July 28, 2024

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

from birdseye-vscode.

Almenon avatar Almenon commented on July 28, 2024

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

from birdseye-vscode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.