--- mkill.c +++ mkill.c 2009-04-29 12:55:49.480409712 +0200 @@ -100,6 +100,7 @@ int main(int argc, char* argv[]) { const pid_t pid = getpid(); const pid_t sid = getsid(0); + const pid_t ppid = getppid(); proc_t * this, *ptr, * last; struct dirent * dent; int dfd, num, nsig = SIGTERM; @@ -210,6 +211,9 @@ int main(int argc, char* argv[]) if (sid == curr) continue; + if (ppid == curr) + continue; + found = false; strcpy(path, dent->d_name); @@ -308,6 +312,8 @@ int main(int argc, char* argv[]) for (ptr = procs; this; ptr = this) { last = ptr->prev; this = ptr->next; + if (ptr->pid != curr) + continue; if (ptr == procs) { if (this) this->prev = (proc_t*)0; procs = this; --- usleep.c +++ usleep.c 2009-04-30 11:40:00.065901445 +0200 @@ -20,20 +20,25 @@ #ifdef __NO_STRING_INLINES # undef __NO_STRING_INLINES #endif +#include +#include #include -#include +#include +#include #include #include +#include +#include +#include +#include #include -#ifdef _POSIX_PRIORITY_SCHEDULING -# include -#endif #define USAGE "Usage:\t%s [ microseconds ]\n", we_are static char *we_are; int main(int argc, char **argv) { unsigned long int usec = 1; + int fd; if (argc > 2) goto err; @@ -45,12 +50,35 @@ int main(int argc, char **argv) goto err; } - if (usec) + if ((fd = open("/dev/null", O_RDWR|O_NOCTTY|O_CLOEXEC)) >= 0) { + dup2(fd, 0); + dup2(fd, 1); + dup2(fd, 2); + if (fd > 2) close(fd); + } + + if (usec) { +#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L) + struct timespec req = {0, 0}, rem = {0, 0}; + int ret; + + while (usec >= 1000000UL) { + req.tv_sec++; + usec -= 1000000UL; + } + req.tv_nsec = usec * 1000; + + do { + ret = nanosleep(&req, &rem); + if (ret == 0 || errno != EINTR) + break; + req = rem; + } while (req.tv_nsec > 0 || req.tv_sec > 0); +#else usleep(usec); -#ifdef _POSIX_PRIORITY_SCHEDULING - else - (void)sched_yield(); #endif + } else + (void)sched_yield(); _exit(0); /* Do this at the end for speed */