How to get rid of the '<defunct>' in running this shell scripts?

How to get rid of the '<defunct>' in running this shell scripts?

Post by Tom Ca » Wed, 25 Jul 2001 03:44:36



Hello, everyone:

I have the following sh scripts (in HP UX and Sun OS):

====================================================
#!/bin/sh

move_it()
{
  count=0
  for files in `echo ${dir_A}/????_pnt.gz`
  do
      dt=`basename ${files} | cut -d_ -f1`
      if [ ${dt} -lt ${today} ]
      then
          mv -f ${files} ${dir_B}
          count=`expr ${count} + 1`
      fi
  done
  echo "Total of ${count} files moved."
  return

Quote:}

today=`date +%y%m`
dir_1=/home/user1/dir1
dir_2=/home/user1/dir2
check_point=`grep DONE ${dir_1}/status.txt`

if [ ${today} = `echo ${check_point} | cut -d: -f1` ]
then
    dir_A=${dir_1}
    dir_B=${dir_2}
    move_it
else
    echo "Please check by hand."
    exit
fi

echo "Done."
====================================================

In the named directory, I have many hundreds of files to move, and I
have to move the files once a month by watching the note in file
"status.txt".

When I run it, it always generates a '<defunct>' process by that
"move_it()" function. I hate this '<defunct>' thing, because I know it
may be turning worse somewhere, but I can't check out where I do wrong
with my scripts.

Can someone help me in checking out how I can solve it?

Thanks.

Tom

 
 
 

How to get rid of the '<defunct>' in running this shell scripts?

Post by David Masterso » Wed, 25 Jul 2001 05:15:14



> I have the following sh scripts (in HP UX and Sun OS):

> ====================================================
> #!/bin/sh

> move_it()
> {
>   count=0
>   for files in `echo ${dir_A}/????_pnt.gz`
>   do
>       dt=`basename ${files} | cut -d_ -f1`
>       if [ ${dt} -lt ${today} ]
>       then
>           mv -f ${files} ${dir_B}
>      count=`expr ${count} + 1`
>       fi
>   done
>   echo "Total of ${count} files moved."
>   return
> }

> today=`date +%y%m`
> dir_1=/home/user1/dir1
> dir_2=/home/user1/dir2
> check_point=`grep DONE ${dir_1}/status.txt`

> if [ ${today} = `echo ${check_point} | cut -d: -f1` ]
> then
>     dir_A=${dir_1}
>     dir_B=${dir_2}
>     move_it
> else
>     echo "Please check by hand."
>     exit
> fi

> echo "Done."
> ====================================================

> In the named directory, I have many hundreds of files to move, and I
> have to move the files once a month by watching the note in file
> "status.txt".

> When I run it, it always generates a '<defunct>' process by that
> "move_it()" function. I hate this '<defunct>' thing, because I know
> it may be turning worse somewhere, but I can't check out where I do
> wrong with my scripts.

I'm not sure where your "<defunct>" process is coming from although I
suspect its the "for" line in the move_it function.  A defunct process
is a process who has exited (successfully or not), but has not yet
been cleaned up (wait()ed for) by its parent.  You mention that the
directory has many hundreds of files to move, so perhaps the defunct
process is only temporary and will go away when the shell script
exits?

p.s. couldn't you do the for statement as the following?

        for files in ${dir_A}/????_pnt.gz

--
David Masterson
Sr. R&D Engineer
Synopsys, Inc.

 
 
 

How to get rid of the '<defunct>' in running this shell scripts?

Post by Villy Kru » Wed, 25 Jul 2001 21:06:19


On 23 Jul 2001 13:15:14 -0700,


>> I have the following sh scripts (in HP UX and Sun OS):

>> ====================================================
>> #!/bin/sh

>> move_it()
>> {
>>   count=0
>>   for files in `echo ${dir_A}/????_pnt.gz`
>>   do
>>       dt=`basename ${files} | cut -d_ -f1`
>>       if [ ${dt} -lt ${today} ]
>>       then
>>           mv -f ${files} ${dir_B}
>>          count=`expr ${count} + 1`
>>       fi
>>   done
>>   echo "Total of ${count} files moved."
>>   return
>> }

>> today=`date +%y%m`
>> dir_1=/home/user1/dir1
>> dir_2=/home/user1/dir2
>> check_point=`grep DONE ${dir_1}/status.txt`

>> if [ ${today} = `echo ${check_point} | cut -d: -f1` ]
>> then
>>     dir_A=${dir_1}
>>     dir_B=${dir_2}
>>     move_it
>> else
>>     echo "Please check by hand."
>>     exit
>> fi

>> echo "Done."
>> ====================================================

>> In the named directory, I have many hundreds of files to move, and I
>> have to move the files once a month by watching the note in file
>> "status.txt".

>> When I run it, it always generates a '<defunct>' process by that
>> "move_it()" function. I hate this '<defunct>' thing, because I know
>> it may be turning worse somewhere, but I can't check out where I do
>> wrong with my scripts.

>I'm not sure where your "<defunct>" process is coming from although I
>suspect its the "for" line in the move_it function.  A defunct process
>is a process who has exited (successfully or not), but has not yet
>been cleaned up (wait()ed for) by its parent.  You mention that the
>directory has many hundreds of files to move, so perhaps the defunct
>process is only temporary and will go away when the shell script
>exits?

>p.s. couldn't you do the for statement as the following?

>        for files in ${dir_A}/????_pnt.gz

It is very likely that the zombie from that echo in the original 'for'
line

   for files in `echo ${dir_A}/????_pnt.gz`

would not be collected until the entire for loop has terminated.
That would give just one zombie for the duration, and should then
go away, and I see no problems with that.  If you have 100 or
more zombies, or one for each file, I would be worried.

Then again, this is an example of a useless use of the echo command.

Villy

 
 
 

How to get rid of the '<defunct>' in running this shell scripts?

Post by Tom Ca » Wed, 25 Jul 2001 21:34:04




> > I have the following sh scripts (in HP UX and Sun OS):

> > ====================================================
> > #!/bin/sh

> > move_it()
> > {
> >   count=0
> >   for files in `echo ${dir_A}/????_pnt.gz`
> >   do
> >       dt=`basename ${files} | cut -d_ -f1`
> >       if [ ${dt} -lt ${today} ]
> >       then
> >           mv -f ${files} ${dir_B}
> >         count=`expr ${count} + 1`
> >       fi
> >   done
> >   echo "Total of ${count} files moved."
> >   return
> > }

> > today=`date +%y%m`
> > dir_1=/home/user1/dir1
> > dir_2=/home/user1/dir2
> > check_point=`grep DONE ${dir_1}/status.txt`

> > if [ ${today} = `echo ${check_point} | cut -d: -f1` ]
> > then
> >     dir_A=${dir_1}
> >     dir_B=${dir_2}
> >     move_it
> > else
> >     echo "Please check by hand."
> >     exit
> > fi

> > echo "Done."
> > ====================================================

> > In the named directory, I have many hundreds of files to move, and I
> > have to move the files once a month by watching the note in file
> > "status.txt".

> > When I run it, it always generates a '<defunct>' process by that
> > "move_it()" function. I hate this '<defunct>' thing, because I know
> > it may be turning worse somewhere, but I can't check out where I do
> > wrong with my scripts.

> I'm not sure where your "<defunct>" process is coming from although I
> suspect its the "for" line in the move_it function.  A defunct process
> is a process who has exited (successfully or not), but has not yet
> been cleaned up (wait()ed for) by its parent.  You mention that the
> directory has many hundreds of files to move, so perhaps the defunct
> process is only temporary and will go away when the shell script
> exits?

> p.s. couldn't you do the for statement as the following?

>         for files in ${dir_A}/????_pnt.gz

Thanks, Dave.

I have tried your way as above, but I guess it is not the command in
that for loop -- I still saw that "<defunct>" appear once a while for
my 'ps -f' results while waiting for the scripts to end.

And yes, they did quit after the scripts were completed. I just wonder
whether I could be save enough when I have these "<defunct>", and
whether they could be doing more harms to the system when I schedule
the scripts as an automatic run.

Can you tell me about this?

Tom

 
 
 

How to get rid of the '<defunct>' in running this shell scripts?

Post by Tom Ca » Thu, 26 Jul 2001 20:59:17



> On 23 Jul 2001 13:15:14 -0700,


> >> I have the following sh scripts (in HP UX and Sun OS):

> >> ====================================================
> >> #!/bin/sh

> >> move_it()
> >> {
> >>   count=0
> >>   for files in `echo ${dir_A}/????_pnt.gz`
> >>   do
> >>       dt=`basename ${files} | cut -d_ -f1`
> >>       if [ ${dt} -lt ${today} ]
> >>       then
> >>           mv -f ${files} ${dir_B}
> >>             count=`expr ${count} + 1`
> >>       fi
> >>   done
> >>   echo "Total of ${count} files moved."
> >>   return
> >> }

> >> today=`date +%y%m`
> >> dir_1=/home/user1/dir1
> >> dir_2=/home/user1/dir2
> >> check_point=`grep DONE ${dir_1}/status.txt`

> >> if [ ${today} = `echo ${check_point} | cut -d: -f1` ]
> >> then
> >>     dir_A=${dir_1}
> >>     dir_B=${dir_2}
> >>     move_it
> >> else
> >>     echo "Please check by hand."
> >>     exit
> >> fi

> >> echo "Done."
> >> ====================================================

> >> In the named directory, I have many hundreds of files to move, and I
> >> have to move the files once a month by watching the note in file
> >> "status.txt".

> >> When I run it, it always generates a '<defunct>' process by that
> >> "move_it()" function. I hate this '<defunct>' thing, because I know
> >> it may be turning worse somewhere, but I can't check out where I do
> >> wrong with my scripts.

> >I'm not sure where your "<defunct>" process is coming from although I
> >suspect its the "for" line in the move_it function.  A defunct process
> >is a process who has exited (successfully or not), but has not yet
> >been cleaned up (wait()ed for) by its parent.  You mention that the
> >directory has many hundreds of files to move, so perhaps the defunct
> >process is only temporary and will go away when the shell script
> >exits?

> >p.s. couldn't you do the for statement as the following?

> >        for files in ${dir_A}/????_pnt.gz

> It is very likely that the zombie from that echo in the original 'for'
> line

>    for files in `echo ${dir_A}/????_pnt.gz`

> would not be collected until the entire for loop has terminated.
> That would give just one zombie for the duration, and should then
> go away, and I see no problems with that.  If you have 100 or
> more zombies, or one for each file, I would be worried.

> Then again, this is an example of a useless use of the echo command.

> Villy

Thanks, Villy.

But I have tried Dave's suggestion of

  for file in ${dir_A}/????_pnt.gz

The zombie was still showing up while running the scripts. Do you have
any ideas on that?

Tom