[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RPM HOW-TO and execution



Felix Kollmann wrote:

> 2.      Can anybody say how to execute programmes in C++ (perhaps 'int exec
> (string name, string path, string params)' o.s.)?

Well, this is more of a UNIX/Linux question than a C++ question.  The
mechanism is identical for all programming languages that support making
OS calls.

  exec/execl/execlp/execle/execv/execvp - this family of functions abort
    the current program and start the new one in it's place.

  system - this function starts up another program, pausing the current
    program until it's finished, resuming after it's done.

  popen - this function starts the other program in parallel to this
    one, creating a 'pipe' between it and the current program so that
    they can exchange data.

If you want to start a program in a parallel thread (ie without pausing
the current program while it runs and without killing the current
program),
then either use popen - or simply call 'fork' to split your program into
two threads and call one of the 'exec' varients to switch that branch of
the fork over to running the other program.  Your main program can then
use 'wait' when it needs to be sure that the other program has finished
executing.
 
RTFM for details.

  man 3 exec
  man 3 system
  man 3 popen
  man 2 fork
  man 2 wait


-- 
Steve Baker                  http://web2.airmail.net/sjbaker1
sjbaker1@airmail.net (home)  http://www.woodsoup.org/~sbaker
sjbaker@hti.com      (work)