I am trying to print running processes on a linux system, but I am getting a segmentation fault when trying to do so. Here is my code:
FILE *ps;
char line[256];
char * command = "ps";
ps = fopen(command, "r");
if(ps == NULL){
perror("Error");
}
while(fgets(line, sizeof(line), ps)){
printf("%s", line);
}
fclose(ps);
The odd thing is that when I use the same code but replace "ps" with "/proc/meminfo" or other files, it will correctly output. Thanks in advance for the help.