#ifndef PROC_H #define PROC_H #include "subprocess.h" #include "io.h" #include "str.h" #include #include #define PROC_UPDATE_DELAY_MS 200 int process_count(char * name){ char command[1024] = {0}; command[0] = 0; strcpy(command,"ps aux"); FILE * pipe = popen(command, "r"); if(pipe == NULL){ perror("popen"); exit(EXIT_FAILURE); } char buffer[1024*1024] = {0}; int count = 0; while(fgets(buffer,sizeof(buffer), pipe) != NULL){ if(count_word_occurences(buffer,name)) count++; } int status = pclose(pipe); if(status == -1){ perror("pclose"); } return count; //WEXITSTATUS(status) } void wait_for_process_count(char * name, uint count){ while(process_count(name) != count){ msleep(PROC_UPDATE_DELAY_MS); } } void wait_new_process(char * name){ int original_process_count = process_count(name); while(process_count(name) < original_process_count + 1){ msleep(PROC_UPDATE_DELAY_MS); } } #endif