Hi i have this process tree:
The above screenshot shows a process tree. In my Perl script i know the PID of dscli. I have written the following code to kill a single PID:
use Win32::Process;
use strict;
use warnings;
if(defined($ARGV[0])){
my $pid = "$ARGV[0]";
my $exitcode = 0;
Win32::Process::KillProcess($pid, $exitcode);
}else{
print "No argument provided :(\n";
}
The problem is that in my script i don't know the java process' PID. I have to get the dscli's child PID which is the java process. If i kill the dscli's PID using the above code then the child(java) don't die with it.
So my question is, how can i kill the java process which is the child of dscli using perl?
Using htop , you can use F5 to show the process tree's. If you select the process at the top of the tree you want kill, then press F9 followed by Enter it will close the process and the entire process tree in one go. In the screen shot below this action would cause Chrome and all sub process to be closed.
To kill the process using PID For Example - To kill Notepad, run the command as, taskkill /PID 2404 /F, where /F is used to kill the process forcefully.
You might can use tasklist to get the process ID of the process you want to target and then use taskkill /F /PID <PID> to kill it.
You can use the Windows command TASKKILL /T
to terminate a process and its child processes.
$pid = ...;
system("TASKKILL /F /T /PID $pid");
It's possible to use WMI from PERL. WMI is able to find the PID of all child processes of a given parent. Note the query "select * from win32_process where ParentProcessId={0}"
. If you have the list of child PIDs, you can call Win32::Process::KillProcess
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With