/* If we hit both windows, it will take three tries to discover the pid. */ int pidof(const char *name) { pid_t p; p = _pidof(name, NULL); if (p < 1) { usleep(10 * 1000); p = _pidof(name, NULL); if (p < 1) p = _pidof(name, NULL); } if (p < 1) return -1; return p; }
int killall(const char *name, int sig) { pid_t *pids; int i; int r; if ((i = _pidof(name, &pids)) > 0) { r = 0; do { r |= kill(pids[--i], sig); } while (i > 0); free(pids); return r; } return -2; }