1754014 Members
7707 Online
108811 Solutions
New Discussion юеВ

Re: Kill Users process

 
Karthick K S
Frequent Advisor

Kill Users process

I want to kill users(not root) process except active sessions how could i write script

PIDS=ps -af | awk '{print $2}'

i received the PIDS but how should i check whether active sessions. and also it should not be root process.
16 REPLIES 16
RAC_1
Honored Contributor

Re: Kill Users process

What exactly are you trying to do?? What do you mean by active sessions?? telnet sessions?? ssh sessions??

The process states changes every millisecond due to time sharing scheduling and so the process which is in running state now may be in wait, sleep, ready to run state after few miliiseconds.

If you want to log out inactive telnet sessions/ssh sessions, you can put TMOUT varibale. export TMOUT=100, will disconnect the session after 100 seconds.

If you want to kill user process, then you can do as follows.

ps -u"user_name|grep -iv [P]ID|awk '{print $1}'|xargs kill -15

Anil
There is no substitute to HARDWORK
Arunvijai_4
Honored Contributor

Re: Kill Users process

Are you trying to kill processes started by particular users and still running eventhough that particular user logged off ?

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Karthick K S
Frequent Advisor

Re: Kill Users process

I want to kill telnet session as well as others process(like dbms).

And daily evening i want to kill inactive sessions i.e only one session should be active(if some users opened 3 session that
time i want to kill 2 sessions except current runing one).
Jeff Schussele
Honored Contributor

Re: Kill Users process

Hi,

I agree with RAC.
This is exactly what the TMOUT variable is designed for - to kill idle sessions.
MUCH safer than just killing processes.

My $0.02,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Karthick K S
Frequent Advisor

Re: Kill Users process

I understand TMOUT is better than kill the process this is only for idle sessions.

But i want to kill if users opened 2 or 3 sessions or process and and also logoff users process except current runing session.
RAC_1
Honored Contributor

Re: Kill Users process

As I said, process state changes very fast. So by the time, you check it and it was running state, it could be be something else, by the time you finished checking it.

You can control no. of logins. man 4 security. Prepare /etc/default/security file and put NUMBER_OF_LOGINS_ALLOWED=2

This will allow 2 simulataneous logins only.
There is no substitute to HARDWORK
Jeff Schussele
Honored Contributor

Re: Kill Users process

Well...the TMOUT will kill the idle shells and because they are the parent PIDs of every thing spawned underneath them, all their children die as well.
It's just MUCH to dangerous to grep stuff out of ps command & kill them. You're likely to kill something that you shouldn't & crash the system.
But I guess if you're a gambling man.....

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Arunvijai_4
Honored Contributor

Re: Kill Users process

Just a note, check this thread before setting /etc/default/security and NUMBER_OF_LOGINS_ALLOWED

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=305690

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Karthick K S
Frequent Advisor

Re: Kill Users process

This is only for kill users process at end of the day only i am not restrict login session.