MCPcopy Index your code
hub / github.com/Xfennec/progress / find_pids_by_binary_name

Function find_pids_by_binary_name

progress.c:176–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176int find_pids_by_binary_name(char *bin_name, pidinfo_t *pid_list, int max_pids)
177{
178int pid_count=0;
179int nb_processes = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0);
180char exe[1024];
181pid_t *pids;
182int i;
183
184pids = malloc(nb_processes * sizeof(pid_t));
185assert(pids != NULL);
186
187proc_listpids(PROC_ALL_PIDS, 0, pids, nb_processes);
188for(i = 0; i < nb_processes; ++i) {
189 if (pids[i] == 0) {
190 continue;
191 }
192 proc_name(pids[i], exe, sizeof(exe));
193 if(!strcmp(exe, bin_name)) {
194 pid_list[pid_count].pid=pids[i];
195 strcpy(pid_list[pid_count].name, bin_name);
196 pid_count++;
197 if(pid_count==max_pids)
198 break;
199 }
200}
201free(pids);
202return pid_count;
203}
204#endif // __APPLE__
205#ifdef __linux__
206int find_pid_by_id(pid_t pid, pidinfo_t *pid_list)

Callers 1

monitor_processesFunction · 0.85

Calls 4

nperrorFunction · 0.85
nfprintfFunction · 0.85
statClass · 0.85
is_numericFunction · 0.85

Tested by

no test coverage detected