I have a function that is supposed to check for user processes and wait for 0 count before exiting the function. I am sure I have more than one issue in my code, but the stumbling block right now is that I am trying to convert the value of my variable from a string to integer.
process_count needs to be an integer to be evaluated in the while loop but while debugging I see that it is " 0" not "0". Any help will be greatly appreciated!
function CheckProcessCount
{
#acively checks user processes for 0 count
curent_user=`whoami`
current_process=$$
parent_process=$PPID
process_count=`ps -ef|grep $current_user|grep -v $current_process|grep -v $parent_process|grep -v grep|grep -v ps|grep -v DomainDaemon|grep -
v -- -ksh|wc -l`
while [[ $process_count != 0 ]]
do ps -ef|grep $current_user|grep -v $current_process|grep -v $parent_process|grep -v grep|grep -v ps|grep -v DomainDaemon|grep -v
-- -ksh|wc -l
done
}
I have changed it to include quotations around the variable in the comparison and use an integer operator, per your suggestion, RudiC and still not working for me:
Isn't there "|kitchen|sink" missing somewhere? ;-))
First, instead of using backticks, please use what is standard in ksh: POSIX-like substitution: $(command|command...) .
Second: instead of doing a "ps -ef" and then grepping out a lot of things you do not need you could limit the output to the processes of a certain user by using the "-u"-option. Most of the other grep s are equally redundant because by grep -v $current_process you already filter out all the children too - they have the current process' PID as their PPID, no?
Then: the output of "wc -l" is not a number, but a text. A text with some leading blanks and this simply does not translate into a number, at least not with the backticks you use. Try the following:
And finally: you want tthe function to wait until the process_count drops to zero. But you set process_count only once and then loop based on the value without ever changing it. Isn't that simply an endless loop if process_count is unequal to 0?
You might want to write something like:
while [ $(ps | [....] | wc -l) -gt 0 ] ; do
sleep 1
done