Kill Process of Current User

Mindwatering Incorporated

Author: Tripp W Black

Created: 05/11/2023 at 11:07 AM

 

Category:
Linux
Utilities

Tasks
Kill running process for the su current user.


Sample:
Stops process for current user except current session.
Skips sshd, bash, ps, and the current file, killmyprocesses.pl.

$ sudo vi /usr/local/bin/killmyprocs.pl

foreach (`ps -u $ENV{USER}`) {
s/^\s+//;
s/\s+$//;
($PID,$TTY,$TIME,$CMD) = split(/\s+/);
next if( $PID eq "PID" or
$CMD eq "sshd" or
$CMD eq "bash" or
$CMD eq "ps" or
$CMD eq "killmyprocs.pl" );
print "killing $PID / $CMD\n";
kill 9, $PID;
}

<esc>:wq, to save.


To use:
$ sudo su
<enter password>
# su userwithstuckprocesses
$ /usr/local/bin/killmyprocs.pl





previous page