execute a program

i would like to start another program from within my program (like system()) but i dont want it to wait for the program to return before continuing (does that make sense?).
im using linux (X.. gtk+ if it matters).
Who is Participating?
fstabConnect With a Mentor Commented:
Use the exec line of functions (exec, execl, execve ... etc.) These are POSIX std. functions which should be available on LINUX.
VickioAuthor Commented:
i cant seem to get any of the exec function to work..
either nothing happens or i get a Seg Fault.
can you give me a little example code?
This was compiled on NT - should work on LINUX too.

#include <stdio.h>
#include <process.h>

main(int argc, char *argv[])
  int count;
  char **cmd_to_exec;
  int flag=0;
  printf("argc is %d\n",argc);
  for(count=0;count < argc; count++) {
     printf("%s ", argv[count]);
     if (!strcmp(argv[count],"-exec") && (count+1) == argc-1) {
        cmd_to_exec = &argv[count+1];
       flag = 1;
  if (flag)
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

VickioAuthor Commented:
i dunno if its the exec i need..
(this is an X program)
i want it to be able to start a program and still stay running itself.
i looked at the source code of a couple programs that do this and they used system() to start the programs... it doessnt work right for me though..
VickioAuthor Commented:
ive also seen the use of an exec and fork to do it.. i cant really figure out what they do there either though..
OK here's what you do -

 int pid;
 pid = fork();
 if (pid == 0) { // child
 } else if (pid) { // parent
   // do your stuff ..
 } else if (pid == -1)
   printf("fork failed");

Doing a fork *and* an exec ensures that the parent and the exec'ed program stay together.
VickioAuthor Commented:
ok, got it.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.