Jack
Jack

Reputation: 16724

How to run a command and don't wait for application exit?

I need to run a command,but that don't lock my application until exit of it,like do system() function.

Upvotes: 0

Views: 245

Answers (2)

Jonathan Leffler
Jonathan Leffler

Reputation: 753585

pid_t pid;

if ((pid = fork()) < 0)
    ...fork failed...
else if (pid == 0)
{
     ...create command line in array of char pointers argv...
     ...sort out I/O -- redirect stdin from /dev/null?...
     execvp(argv[0], argv);
     ...report exec failed on stderr...
     _exit(126);
}
...parent process...gets on with life...

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798546

Use fork() to create a new process, and exec*() to replace it with a new application.

Upvotes: 7

Related Questions