Jump to content

How to auto kill long running clients on Windows?


Recommended Posts

Posted

Hey - looking to kill any clients which run for more than >30 minutes on Windows; preferably via a batch file/exe.

I know they exist for Linux in shell file sofmr; such as;

#!/bin/bash
# This script will kill process which running more than X hours
# egrep: the selected process; grep: hours
PIDS="`ps eaxo bsdtime,pid,comm | egrep "spamd|exim|mysqld|httpd" | grep " 1:" | awk '{print $2}'`"

# Kill the process
echo "Killing spamd, exim, mysqld and httpd processes running more than one hour..."
for i in ${PIDS}; do { echo "Killing $i"; kill -9 $i; }; done;

Just wondering if anyone has ever found a way to kill clients (via process ID/the program name - OSBot.jar) which exceed the time limit set? (In this case 30 minutes).

This is to kill tutorial island clients which either don't connect to the proxy and/or get stuck - to prevent CPU hogging of the server.

 

Thanks

Posted
11 minutes ago, Void said:

Hey - looking to kill any clients which run for more than >30 minutes on Windows; preferably via a batch file/exe.

 

Personally I store all booted credentials and if a client with those details doesn't post back to the server within X time It's killed via pid by CLI username
Windows I use

WMIC path win32_process get Caption,Processid,Commandline

to output CLI/PID/ECT, just loop through each line of the proccess output until line contains details
then after removing all double spaces down to 1 space gaps only

 String pid = s.split(" ")[s.split(" ").length - 1];
 String cli = s.substring(s.indexOf("java -jar")).replace(pid, "");

now we got those we can

Taskkill /PID "+ pid+ " /F"


For linux I have something similar
but

ps -fea|grep -i *CLI USERNAME*

than same as above, make all multiple spaces 1 space gaps

String pid = s.split(" ")[1];
//Note CLI output will depend on if you're running debug mode or not, if you are it'll be the exact args else it'll be the clients main args which are a little more annoying to rip
                       if (s.contains("java -jar")) {
                            cli = s.substring(s.indexOf("java -jar"));
                        }else if(!s.contains("java -jar")) {
                            cli = s.substring((s.indexOf("BotApplication") + ("BotApplication").length()));
                        }

and for the killarino

"kill -9 "+pid;



 

  • Like 4
Posted (edited)

You need to know the Process ID's (PID) to kill the clients, if you start the clients via a Java application you can for example store the PID and a 'started' timestamp in a list for each client. Let a separate thread iterate trough the list and check if the timestamp is older than 30 minutes, if it is kill the process using the PID and remove it from the list.

Or do what @Isolate said.

Edited by Rudie
  • Like 1
Posted
58 minutes ago, Isolate said:

Personally I store all booted credentials and if a client with those details doesn't post back to the server within X time It's killed via pid by CLI username
Windows I use


WMIC path win32_process get Caption,Processid,Commandline

to output CLI/PID/ECT, just loop through each line of the proccess output until line contains details
then after removing all double spaces down to 1 space gaps only


 String pid = s.split(" ")[s.split(" ").length - 1];
 String cli = s.substring(s.indexOf("java -jar")).replace(pid, "");

now we got those we can


Taskkill /PID "+ pid+ " /F"


For linux I have something similar
but


ps -fea|grep -i *CLI USERNAME*

than same as above, make all multiple spaces 1 space gaps


String pid = s.split(" ")[1];
//Note CLI output will depend on if you're running debug mode or not, if you are it'll be the exact args else it'll be the clients main args which are a little more annoying to rip
                       if (s.contains("java -jar")) {
                            cli = s.substring(s.indexOf("java -jar"));
                        }else if(!s.contains("java -jar")) {
                            cli = s.substring((s.indexOf("BotApplication") + ("BotApplication").length()));
                        }

and for the killarino


"kill -9 "+pid;



 

Thanks for the replies  

Where do you store the booted credentials?

Posted
35 minutes ago, Void said:

Thanks for the replies  

Where do you store the booted credentials?

I just have a jar called the "manager"
that I run which I launch clients through, they're stored in  a hashmap of String for username and long for the time that client should be filtered and killed because it didn't post back
Once it's posted it's socket back it'll move from the pending list to a client list which'll just be String for the username and in my case BotCommunicationClient for the communication 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...