Operating System - HP-UX
1753500 Members
4145 Online
108794 Solutions
New Discussion юеВ

Re: profile: cannot fork: too many processes

 
SOLVED
Go to solution
someoneElse_1
Occasional Advisor

Re: profile: cannot fork: too many processes

please find the attachment
ps -fu scott > abc.txt
Bill Hassell
Honored Contributor

Re: profile: cannot fork: too many processes

> ps -ef | grep scott | awk {'print $2'} | xargs kill -9

VERY BAD CODE.

grep and ps can cause catastrophic results, especially when combined with kill. Never use grep to look for a user. Never use kill -9 as you can damage databases and application files.

To kill all the processes owned by scott, FIRST list all of them:

ps -fu scott

Then is all of them are OK to kill, you can apply the kill (and kill -1 if necessary):

ps -fu scott | awk '{print $2}' | xargs kill
and
ps -fu scott | awk '{print $2}' | xargs kill -1

That should take care of all the processes, but just to make sure:

ps -fu scott

grep will find things (partial user names, arguments on the command line, etc) you did not intend to be found.


Bill Hassell, sysadmin
someoneElse_1
Occasional Advisor

Re: profile: cannot fork: too many processes

sure. Point is noted. Thanks for the correction.
someoneElse_1
Occasional Advisor

Re: profile: cannot fork: too many processes

I am not able to kill these scott owned processes
It automatically gets created even after killing all processes owned by scott.

ps -fu scott | awk '{print $2}' | xargs kill
and
ps -fu scott | awk '{print $2}' | xargs kill -1

Count always remains the same :
ps -fu scott | wc -l
514


One more question
By parent-id is 1
scott 17613 1 0 17:52:18 ? 00:00:00 -ksh
scott 10636 1 0 17:48:54 ? 00:00:00 -ksh
scott 16406 10636 0 17:51:58 ? 00:00:00 -ksh
scott 16470 16406 0 17:52:00 ? 00:00:00 -ksh
scott 16620 16470 0 17:52:02 ? 00:00:00 -ksh
-3 16619 16470 0 17:52:02 ? 00:00:00
-3 16623 16406 0 17:52:02 ? 00:00:00
-3 14613 10636 0 17:50:58 ? 00:00:00
Mel Burslan
Honored Contributor

Re: profile: cannot fork: too many processes

put this code below in a file:

vi /tmp/cleaner

{ cut below excluding this line }

#!/usr/bin/sh
ps -fu scott | while read line
do
PID=$(echo $line | awk {'print $2'}
PPID=$(echo $line | awk {'print $3'}
if [ $PPID -eq 1 ]
then
kill $PID
ps -ef | grep $PID; r=$?
if [ $r -eq 0 ]
then
kill -1 $PID
fi
ps -ef | grep $PID; r=$?
if [ $r -eq 0 ]
then
echo "Process $PID won't die"
fi
fi
done

{ cut above excluding this line }

make it executable

chmod 700 /tmp/cleaner

run it

/tmp/executable >/tmp/cleaner.out 2>&1

please post /tmp/cleaner.out here

________________________________
UNIX because I majored in cryptology...
Dennis Handly
Acclaimed Contributor

Re: profile: cannot fork: too many processes

>ME: It seems scott may be using lots of rksh?

(lsof picked the first hardlink as the name.)

>Alzhy: Can you kill all of its processes right now in aid of diagnosis?

Much easier to do:
kill $(UNIX95=EXTENDED_PS ps -u scott -opid=)
Then change to kill -HUP then -9.

>Bill: ksh starts ksh starts ksh starts ksh

You have this with clearcase's setview.

>Then start killing the top level processes.

Right, a lot of them have init as the parent, possibly indicating they didn't log off correctly.

>I need to kill the script causing the issue?

Yes. You did that if you killed all of scott's PIDs.

>Mel: killing the parent process is killing all the children processes before your kill gets to them.

Right, that also reaps the zombies.

>please find the attachment
ps -fu scott > abc.txt

Please use this instead:
UNIX95=EXTENDED_PS ps -H -fu scott > abc.txt

It seems strange you still have lots of processes. You likely have a fork bomb with every process trying to create more, no matter which you kill.
Or it could be a problem with .profile/.kshrc since I don't see any scripts or options on any of the ksh entries.

You may want to stop them all then kill them:
kill -STOP $(UNIX95=EXTENDED_PS ps -u scott -opid=)
kill $(UNIX95=EXTENDED_PS ps -u scott -opid=)

>Bill: ps -fu scott | awk '{print $2}' | xargs kill

No need to use awk and xargs:
kill $(UNIX95=EXTENDED_PS ps -u scott -opid=)

>One more question. By parent-id is 1
>scott 17613 1 0 17:52:18 ? 00:00:00 -ksh

Right, these orphans have had their parent killed and are adopted by init.

>Mel: put this code below in a file:

My "kill -STOP" will probably be easier.
someoneElse_1
Occasional Advisor

Re: profile: cannot fork: too many processes

Please find cleaner.out output attached.

ps -fu scott | wc -l
514

Dennis Handly
Acclaimed Contributor

Re: profile: cannot fork: too many processes

>Please find cleaner.out output attached.

This gives a lot of bogus output due to what Bill said about ps and grep.

Instead of doing:
ps -ef | grep $PID; r=$?
if [ $r -eq 0 ]; then
Do:
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]; then
Or:
kill -0 $PID 2> /dev/null
if [ $? -eq 0 ]; then

Anyway, this is moot, since you need that -STOP first.
Alzhy
Honored Contributor

Re: profile: cannot fork: too many processes

Try:

kill -9 `ps -ef|grep -w scott|awk '{print $2}'`
ps -fu scott|wc -l
ps -ef -u scott|tee scott.txt

Paste so there is no "wait" in between...
Hakuna Matata.
someoneElse_1
Occasional Advisor

Re: profile: cannot fork: too many processes

#!/usr/bin/sh
ps -fu scott | while read line
do
PID=$(echo $line | awk {'print $2'}
PPID=$(echo $line | awk {'print $3'}
if [ $PPID -eq 1 ]
then
kill -0 $PID 2> /dev/null
if [ $? -eq 0 ]; then
kill -1 $PID 2> /dev/null
fi
if [ $? -eq 0 ]
then
echo "Process $PID won't die"
fi
fi
done


Dennis where to put -STOP in above code
is above code ok to run