0

I have an application that parses the output from a command line using popen. However, when tested on Android, it crashes on pclose: Why? When tested in other Unix environment I have no error...

char commandLine[256] = "ps -A | grep -c myApplication";

FILE * fPipe = popen(commandLine, "r");

if (fPipe == NULL)
    return 0;

int count = -1;
fscanf(fPipe, "%d", &count);

///If here I print count, I get zero, which is correct...

pclose(fPipe); ///Here it crashes!

return count;

Update: It seems that using popen causes my application to crash anyway, at a later as stage, as if doing this call kills my application.

Antonio
  • 19,451
  • 13
  • 99
  • 197

1 Answers1

0

popen uses fork which apparently shouldn't be used in Android. To see which processes are running probably the only safe way is to check in the /proc dir. More reading: popen on android NDK

Community
  • 1
  • 1
Antonio
  • 19,451
  • 13
  • 99
  • 197