Alex Rivera | Logout

Non-blocking version of system()

Asked 2009-06-16T16:14:13.930
28

I want to launch a process from within my c program, but I don't want to wait for that program to finish. I can launch that process OK using system() but that always waits. Does anyone know of a 'non-blocking' version that will return as soon as the process has been started?

[Edit - Additional Requirement] When the original process has finished executing, the child process needs to keep on running.

Edit
Report

2 Answers

24

One option is in your system call, do this:

 system("ls -l &");

the & at the end of the command line arguments forks the task you've launched.

answered 2009-06-16T16:16:55.897
1

You could use posix_spawnp() function. It's much similar to system() than the fork and exec* combination, but non-blocking.

answered 2009-06-21T14:42:51.657

Your Answer