added kill script
This commit is contained in:
parent
24b277e12e
commit
6a80f8eefa
28
src/utils/kill.ts
Normal file
28
src/utils/kill.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { NS } from '@ns';
|
||||||
|
|
||||||
|
export const kill = (ns: NS, hostname: string) => {
|
||||||
|
// get a list of all the running processes on the specified host
|
||||||
|
const processes = ns.ps(hostname);
|
||||||
|
|
||||||
|
let killedProcesses = 0;
|
||||||
|
let killedThreads = 0;
|
||||||
|
let memFreed = 0;
|
||||||
|
|
||||||
|
processes.forEach((process) => {
|
||||||
|
// calculate the amount of memory that will be freed by killing this process
|
||||||
|
memFreed = process.threads * ns.getScriptRam(process.filename);
|
||||||
|
|
||||||
|
// kill each process by its pid
|
||||||
|
ns.kill(process.pid);
|
||||||
|
|
||||||
|
// update the counters
|
||||||
|
killedProcesses++;
|
||||||
|
killedThreads += process.threads;
|
||||||
|
memFreed += memFreed;
|
||||||
|
});
|
||||||
|
|
||||||
|
ns.tprint(`Killed processes on ${hostname}:`);
|
||||||
|
ns.tprint(`Processes killed: ${killedProcesses}`);
|
||||||
|
ns.tprint(`Threads killed: ${killedThreads}`);
|
||||||
|
ns.tprint(`Memory freed: ${memFreed} GB`);
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue