• Uncategorized

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

Question Detail

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('\r\n')
    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.

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.