yellowta has asked for the wisdom of the Perl Monks concerning the following question:

The environment is AIX 7.1 and perl 5.10. I run a script that emulates a tail -f on a log file and writes some records to another file. When looking at the output of a "ps" statement, I see processes called "perl" pop up and then go away. Usually there are two, one has a parent of 1, and the other has a parent of the original script. Anybody have any information was to what these process are doing and what creates them? Thanks!

Replies are listed 'Best First'.
Re: What is this process
by shmem (Chancellor) on Sep 26, 2016 at 19:28 UTC
    I run a script that emulates a tail -f on a log file and writes some records to another file. When looking at the output of a "ps" statement, I see processes called "perl" pop up and then go away.

    Hard to tell from afar without knowing how you implemented your emulation of tail -f. Are you using a module, e.g. File::Tail, Event::File::tail or such? are you using backticks, piped open? If you posted your script, we wouldn't need to guess.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      Thanks! I think I have figured it out. I don't use a module. At EOF, I do a seek(IN, 0, 1) to reset EOF, and continue reading. I think it is the seek that is generating the processes. Quite a few more records are written to the log file that I am reading than I echo out. So, I probably do much more reading after hitting EOF. The timing makes sense. Also, I have another script that does a similar thing, except that it does not echo anything out. It has been running for a year. Never paid much attention to it. When I started watching for the perl processes on that box, it was doing the same thing. So the only thing in common between those two scripts is the seek. I think the fickle finger of fate is pointed squarely at the seek. Thanks again!
        I think it is the seek that is generating the processes.

        No. perl's seek doesn't imply spawning a new process. It boils down to a system call done in the same process, on my system (Linux) it is lseek(2).
        Does perl sport an echo function (see perlfunc)? There.

        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: What is this process
by GotToBTru (Prior) on Sep 26, 2016 at 19:04 UTC

    There are commands like system and exec that perform an implicit fork. Is this perhaps what you are seeing?

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      I have isolated a section of code that appears to be related to the rogue processes. In that section the only command like that I do is one like 'echo "$xxx" >>$file`. I guess that is an implicit system command. I could buy this except the ratio of records processed to the processes does not seem to match. A process does not pop up for each execution of the echo. In that section is also do a seek command. This is executed to reset the EOF file when I hit EOF on the input file. Could that do it? Thanks for the response? I am starting to pull my hair out trying to figure this out.

        echo is a system command so perl will have to start a shell to run that, so yes, it will start a new process for each call to echo.

        Even if they are happening too fast for you to see.

        BTW, that's not very efficient, so you'd be better just using perl to do that, open can open a file for append.