1827280 Members
2375 Online
109717 Solutions
New Discussion

Re: kill process

 
SOLVED
Go to solution
Michael_33
Regular Advisor

kill process

Hi All,

I want to kill all process which the owner is user1,how should I do?

Thanks!
20 REPLIES 20
Michael Tully
Honored Contributor

Re: kill process

Hi,

This should kill all processes related to user1. If the first one doesn't work the second should. You must be 'root' to perform this function properly.

# ps -ef | grep user1 | awk '{print $2}' | xargs kill -5
# ps -ef | grep user1 | awk '{print $2}' | xargs kill -9


Cheers
~Michael~
Anyone for a Mutiny ?
steven Burgess_2
Honored Contributor

Re: kill process

Hi

I use the following script which will prompt you for a username

echo "\nkill process script"
echo "====================="

listfile1=/tmp/rm_process.list
listfile2=/tmp/rm_process.list2
sleep 1
echo "Please enter you choice of process"
read choice

rm -f $listfile1 $listfile2 2>&1

ps -ef | grep $choice | cut -c10-15 > $listfile1
sed 's/^/kill -15/g' $listfile1 > $listfile2
chmod 777 $listfile2
$listfile2

echo "\nkill process script ends"

Regards

Steve
take your time and think things through
Michael_33
Regular Advisor

Re: kill process

thanks!

one more question:

I found the cron daemon is start by user1!
I try to kill -9 pid, but doesn't work! how should I do?
steven Burgess_2
Honored Contributor

Re: kill process

Hi

/sbin/init.d/cron stop

to restart

/sbin/init.d/cron start

Regards

Steve
take your time and think things through
steven Burgess_2
Honored Contributor

Re: kill process

Michael

I picked up this info from 'Bill Hassell'
regarding processes. Have a read it's very interesting

Steve
take your time and think things through
Michael_33
Regular Advisor

Re: kill process

Hi Steven,

I did this already, but doesn't work. Any idea?
steven Burgess_2
Honored Contributor

Re: kill process

Hi

Can you post the output of your

ps -ef | grep cron

Cheers

Steve
take your time and think things through
Michael_33
Regular Advisor

Re: kill process

user1 17290 1 07:56 ? /usr/sbin/cron

steven Burgess_2
Honored Contributor

Re: kill process

Hi

It looks as though the process appears to be hung, when you look at it from top, is it sleeping ? If so the kill may be ignored

I've done a quick search and found the following doc

A reboot may sound a little drastic but may cure the problem

http://forums.itrc.hp.com/cm/components/FileAttachment/0,,0x4c04a22d6d27d5118fef0090279cd0f9,00.htm

Have a read through

Regards

Steve

take your time and think things through
Michael Tully
Honored Contributor

Re: kill process

Hi,

That is a very interesting document, and the information is a good starting point. Rarely have I seen a 'hung' cron process. In saying that the 'cron' process should run as user 'root'. Is that the case on your system, using 'user1' as an example?

Is the 'cron' process still logging jobs to the cron log? (/var/adm/cron/log)

I agree, that the last resort will be a system reboot.

Michael
Anyone for a Mutiny ?
Michael_33
Regular Advisor

Re: kill process

no other way, only reboot?
Michael_33
Regular Advisor

Re: kill process

Michael, you are right, user1 just an example.
the cron's log is stopped already.
but the cron daemon is still running, maybe
hung already. kill -9 doesn't work, the value
of w is >100!

Michael Tully
Honored Contributor
Solution

Re: kill process

Hi Michael,

If there are critical jobs from cron that need to run, try to run them manually until you can schedule a system reboot. I see no other alternative, if the cron process has 'hung'.

Good Luck
~Michael~
Anyone for a Mutiny ?
steven Burgess_2
Honored Contributor

Re: kill process

Hi

Just had major issues attempting to reply

As per Micheal's comments, run the jobs manually. The doc states

NOTE: Only restarting the machine can free up the resources used by
a hung unsignalable process.

CAUTION: Anytime you have unkillable processes issuing a shutdown command
may cause the system to hang during shutdown. The reboot command
is a better alternative. Use reboot(1m) after stopping all
processes (See killall script) and umounting all filesystems that
can be umounted.

Note: using reboot, killall is in /sbin/init.d

Good luck

Steve
take your time and think things through
Michael_33
Regular Advisor

Re: kill process

Thanks all!
Michael Tully
Honored Contributor

Re: kill process

Hi Michael,

Now would also be a perfect opportunity to look at planning for the future and to patch your system(s). Given that a hung process can also be an unexpected condition in the system kernel may indicate that there is a bug.

HTH
~Michael~
Anyone for a Mutiny ?
Trevor Roddam_1
Valued Contributor

Re: kill process

I would also check the passwd file for users with UID 0 other than root.
Just in case.
Baldric, I have a plan so cunning you could pin a tail on it and call it a weasle.
steven Burgess_2
Honored Contributor

Re: kill process

Hi

Very good point

Steve
take your time and think things through
Jack Werner
Frequent Advisor

Re: kill process

I'm going to take this oppurtunity to repeat a mantra of mine. When will someone request POSIX to change the kill command so it doesn't require the "approval" of the intended victim? If a process is not "signalable" and is the desired target of "kill", then the kill command should remove the victim from the process stack. The system termination cleanup module should have logic sufficient to perform this task. Another approach would be to have the kill command "spoof" the completion of whatever the victim might be waiting for. Then, when his head pops up, give him a 357 between the eyes. Rebooting is an uacceptable option to kill a rogue process
i'm retired
Ahmed Masud
New Member

Re: kill process


[[Assuming you are using the HP-UX cron and not an extention]]



If rebooting is a problem and you wish to not run the cron jobs by hand then move the cron related fifo:

mv /var/adm/cron/FIFO /var/adm/cron/FIFO.old

create a new FIFO

mknod /var/adm/cron/FIFO p

And run cron again as root:

/usr/sbin/cron

This should start a clean cron that can continue to work.

Hopefully your /var is not an NFS :-).

A possible reason why your /usr/sbin/cron is not responding is because some parent process is stuck.



I hope this will resolve your problem.

Cheers,

Ahmed.