I was running some processes under a screen session on a remote server. When I tried to kill all those processes by:
pkill -U tim
all my processes are killed including those I don't want to kill (i.e. the screen and ssh connection).
Is there a way to kill all my processes except the screen and ssh connection?
Best Answer
Kinda hackerish:
this will kill everything but any ssh or screen processes. Here are the commands explained:
ps -U tim
-- will obviously, list every process from the user timegrep -v "ssh|screen"
-- will remove lines with ssh or screen processescut -b11-15
-- will cut the data in columns 11-15 (typically that's where the PID is locatedxargs -t kill
-- will pass all the process ID's to the kill commandYou can also use awk, if you're more used to that.