Re: Fork, exec - setsid?

From: Anno Siegel (anno4000_at_lublin.zrz.tu-berlin.de)
Date: 11/23/04


Date: 23 Nov 2004 15:02:28 GMT

Robert Manea <rob@nova.hbx.us> wrote in comp.lang.perl.misc:
> Hello everyone,
>
> I'm trying to solve a quite simply looking job but can't really come up
> with an elegant working solution.
>
>
> The why:
> --------
>
> I wrote a frontend to a DVB (digital video broadcasting) card in
> Gtk2 using Perl. So I came up with the need to fork some processes away
> and execute a couple of external programs via 'exec()'; these programs
> are linked together via pipes.
>
> The DVB-card is built in a remote machine so I first have to fork away a
> new process and do:
>
> exec('ssh remote-machine start-the-dvb-stuff-and-multicast-it')
>
> after that fork away another process and:
>
> exec('grab-the-stream | demultiplex-it | videoplayer').
>
>
> The problem:
> ------------
>
> As exec normally never returns and spwans a shell when it finds any
> metachars in the command to be executed there is no means to get the PID
> of those or the spawned shell.

The shell will have the pid that fork() returned to the parent.

> But unfortunatelly I have to quit those processes every time the user
> wants to switch channels via the parent.
>
>
> The question:
> -------------
>
> How do I kill the forked away programms without knowing their PID?
> Or better, how to kill them based on their SID?

Kill the shell that runs the pipeline. You have the pid.

Anno



Relevant Pages

  • Re: External Unix programme - time limit
    ... checking if the process is still active after the sleep. ... >> kill the right programme...and when using the syntax you ... > You don't need to know the PID, %1 is the first job running in the ... > shell, which should be your ./senkin.e program. ...
    (comp.soft-sys.matlab)
  • Re: Wait for background processes to complete
    ... trying to use the shell concepts and maximize parallelism). ... the systemcommand - which leaves us back at square one. ... fork, and then do your own wait. ... PID PGID COMMAND ...
    (comp.lang.perl.misc)
  • Re: Redirecting output from "kill" command?
    ... that's written to stderr by the parent shell whose child has been killed, ... not by the kill command itself. ... Pid 25165 is the parent shell, pid 25797 is the sleep process which we ...
    (comp.unix.misc)
  • Re: tk - running always
    ... $pid = fork; ... Then how to end it, was either kill it with kill 9,. ... There seems to be a patch question with Tk and fork. ...
    (comp.lang.perl.tk)
  • Re: Wait for background processes to complete
    ... have the perl program wait for the commands to complete. ... This starts a shell, which then starts cp in the background. ... to use fork and system or fork and exec. ... of the process, but - if it's the pid of the shell process, then we're ...
    (comp.lang.perl.misc)