#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main() {
int res = system("ps ax -o pid -o command | grep sudoku | grep gnome > /dev/null");
printf("res = %d \n", res);
return 0;
}
I want to see if sudoku is running or not by just examining the return code of system() (or any other call for that matter). I do not want any output to be printed anywhere.
I do not quite understand the return code of system() even after looking at the man page
Whether sudoku is running or not, I get res = 0.
The way you are trying to capture the output of
grepmay not work.Based on the post:
C: Run a System Command and Get Output?
You can try the following. This program uses popen()
For reference to popen() see:
http://linux.die.net/man/3/popen
And if you try to use
grepthen you can probably redirect the output ofgrepand read the file in the following way: