gln
gln

Reputation: 1031

Get service status in c++ linux

in my c++ application in linux how can I get a service status (like service abc status in terminal when the abc is the service)

thanks

Upvotes: 0

Views: 3330

Answers (1)

Erik
Erik

Reputation: 91270

FILE * f = popen("service abc status", "r");

Then read from f with e.g. fgets

char Line[100];
while (fgets(Line, 100, f) != NULL)
    cout << Line;

Remember to close the file:

int st = pclose(f);

Then you can check the exit code and such using the macros described in "man 2 wait" on st

Upvotes: 3

Related Questions