in

Using subprocess find out running node application with pid and port using python


I am trying to make a script where I can find out all running node applications with PID and Port. Then using a particular port number I can kill that process.

here is my code

def Test():
    output = subprocess.check_output(('TASKLIST', '/FO', 'CSV')).decode()
    # get rid of extra " and split into lines
    output = output.replace('"', '').split('rn')
    keys = output[0].split(',')
    proc_list = [i.split(',') for i in output[1:] if i]
    # make dict with proc names as keys and dicts with the extra nfo as values
    proc_dict = dict((i[0], dict(zip(keys[1:], i[1:]))) for i in proc_list)

    for name, values in sorted(proc_dict.items(), key=lambda x: x[0].lower()):
        if name == "node.exe":
            print('%s: %s' % (name, values['PID']))
            os.kill(int(values['PID']), signal.SIGILL)
        else:
            pass
    return "done"

Using this code, I can find all Node Application but not able to kill specify Port. It’s killing all the port on server.

Help me out to on this. If need more info connect with me in chat.

Thanks in advance.



Source: https://stackoverflow.com/questions/70558964/using-subprocess-find-out-running-node-application-with-pid-and-port-using-pytho

Quick Tip: Java Message Service Class

PowerDNS 4.x API bindings for Golang