Linux kill all user process without own session

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Linux kill all user process without own session

Eren
Hi Erman,

How to kill all user process without kill the shell that is running the script?

I tried sth;

kill -9 `ps -ef |grep erenu|grep -v grep |grep -v $$ |awk '{print $2}'`

this one also kill my own shell,
I need to kill all process without kill my login session
Reply | Threaded
Open this post in threaded view
|

Re: Linux kill all user process without own session

ErmanArslansOracleBlog
Administrator

are you connecting via root? I mean from root using su - youruser  ?

25 Kas 2014 21:52 tarihinde "Eren [via Erman Arslan's Oracle Forum]" <[hidden email]> yazdı:
Hi Erman,

How to kill all user process without kill the shell that is running the script?

I tried sth;

kill -9 `ps -ef |grep erenu|grep -v grep |grep -v $$ |awk '{print $2}'`

this one also kill my own shell,
I need to kill all process without kill my login session


If you reply to this email, your message will be added to the discussion below:
http://erman-arslan-s-oracle-forum.2340467.n4.nabble.com/Linux-kill-all-user-process-without-own-session-tp132.html
To start a new topic under Linux, email [hidden email]
To unsubscribe from Erman Arslan's Oracle Forum, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: Linux kill all user process without own session

ErmanArslansOracleBlog
Administrator
kill `ps -o pid= -N T`

Try and test the following command on a TEST environment first.

-N              Select all processes except those that fulfill the specified conditions. (negates the selection) Identical to --deselect.

T               Select all processes associated with this terminal

-o format       user-defined format

These are sensitive commands.

VERY IMPORTANT ! use this command when you are a non-root user, because the command try to kill the root processes too..

Reply | Threaded
Open this post in threaded view
|

Re: Linux kill all user process without own session

ErmanArslansOracleBlog
Administrator
Also "killall5" command can be tried..
Here is the important info about it : "sends a signal to all processes except kernel threads and the processes in its own session, so it wont kill the shell
       that is running the script it was called from."


KILLALL5(8)           Linux System Administratorâs Manual          KILLALL5(8)

NAME
       killall5 -- send a signal to all processes.

SYNOPSIS
       killall5 -signalnumber

DESCRIPTION
       killall5  is  the SystemV killall command. It sends a signal to all processes except kernel threads and the processes in its own session, so it wont kill the shell
       that is running the script it was called from. Its primary (only) use is in the rc scripts found in the /etc/init.d directory.

SEE ALSO
       halt(8), reboot(8)

AUTHOR
       Miquel van Smoorenburg, miquels@cistron.nl

                                  04 Nov 2003                      KILLALL5(8)