Keiros
Keiros

Reputation: 101

Running Blocking Function in Background

I am trying to run a program that essentially runs forever. I need to start it with certain parameters that I load in so I am running it from within my c++ program. Say this is the program.

int main() {
   while(true) {
     // do something
   }
}

It compiles to a shared library object: forever.so.

If I do the following from c++ nothing happens.

int main() {
  system("forever.so &");
}

If I do the following my program blocks forever (as would be expected).

int main() {
  system("forever.so");
}

What am I doing wrong here?

I can provide the strace and other info.

To be clear. The issue is that if I check processes with

ps -a 

I do not see any of my processes. This is when the program is paused during a debug session so the processes should still be alive.

Upvotes: 0

Views: 137

Answers (1)

Aplet123
Aplet123

Reputation: 35482

system uses /bin/sh, which is a POSIX shell. & after a command means to run it in the background, which means it won't block. Read here for more info.

Upvotes: 3

Related Questions