YOu can do this with a combination of ps , awk and kill:
ps -eo pid,etime,comm
Gives you a three column output, with the process PID, the elapsed time since the process started, and the command name, without arguments. The elapsed time looks like one of these:
mm:ss
hh:mm:ss
d-hh:mm:ss
Since you want processes that have been running for more than a week, you would look for lines matching that third pattern. You can use awk to filter out the processes by running time and by command name, like this:
ps -eo pid,etime,comm | awk '$2~/^7-/ && $3~/mycommand/ { print $1 }'
which will print the pids of all commands matching 'mycommand' which have been running for more than 7 days. Pipe that list into kill, and you're done:
ps -eo pid,etime,comm | awk '$2~/^7-/ && $3~/mycommand/ { print $1 }' | kill -9
From the man page :
-X Send the specified command to a running screen session. You can
use the -d or -r option to tell screen to look only for attached
or detached screen sessions. Note that this command doesn't work
if the session is password protected.
You can do :
screen -X -S <sessionid> kill
Best Answer
This kills all processes except the ones associated with the current terminal: