0

I am using fork and execv to spawn child programs. How can I make these programs run in the background? I tried not waiting for them, but they still send output to the screen.

node ninja
  • 31,796
  • 59
  • 166
  • 254

2 Answers2

3

Redirect stdout/stderr to /dev/null before you exec:

freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
exec....
Erik
  • 88,732
  • 13
  • 198
  • 189
1

You can use pipe to redirect output of child process. Take a look to this queston. There is code what doing redirection of stdout and stderr to pipe.

Community
  • 1
  • 1
Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111