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

Hi all! I have a problem to understand how job control works in perl, I want to implement job control in my home made unix shell to list which processes are running in the background. And then I want to use "fg" to switch a background process to run in the foreground. I know how to access the builtin commands but thats all.. Im not an expert in Perl programming so I have absolutely no idea how to get this thing working.. plz can anybody give me a hint?

Replies are listed 'Best First'.
Re: Job control
by Fletch (Bishop) on Nov 28, 2005 at 15:42 UTC

    Find a copy of Advanced Programming in the UNIX Environment (ISBN 0201433079) and read chapter 9, "Process Relationships", for what should be everything you need to know about implementing job control (and if you're writing your own shell you should already have a copy at hand anyhow :). You might also find the relevant portions of the code to zsh or bash to be of use.

Re: Job control
by Moron (Curate) on Nov 28, 2005 at 15:51 UTC
    The facilities you describe are already delivered with unix (see man fg and it'll tell you about all the related commands). They can be found under Solaris in /usr/bin. When executing these from Perl (e.g. with the system command) there will be a shell process in between, so you'll have to give fg or bg the specific pid as argument. But you can get the pid when creating the background job, for example, if spawning it using Proc::Simple.

    Update: To be more precise about the last point, having used the new and start methods, you can then use the pid method to retrieve its pid.

    -M

    Free your mind

Re: Job control
by ambrus (Abbot) on Nov 28, 2005 at 22:30 UTC

    The "Job Control" section of gnu libc info documentation can help a lot, it even has nice examples.