[Bug 341239] Re: kill(2) succeeds when no process corresponds to the given PID
Glyph Lefkowitz
glyph at divmod.com
Mon Mar 30 17:13:35 UTC 2009
In case anyone still doubts that this is a kernel (or libc) issue, and
thinks it's a Python issue, here's a similar program in C. Note that
this dies even though we are killing an internal thread ID and not the
process's PID.
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#define REASONABLE 1024
void* my_thread (void *threadid) {
printf("thread started\n");
sleep(600000);
pthread_exit(NULL);
}
int main(int argc, char** argv) {
pthread_t thread;
long t;
int rc;
char taskdir[REASONABLE];
char mypid[REASONABLE];
snprintf(mypid, REASONABLE, "%ld", (long) getpid());
rc = pthread_create(&thread, NULL, my_thread, (void *)t);
printf("main pid %ld\n", (long) getpid());
snprintf(taskdir, REASONABLE, "/proc/%s/task", mypid);
DIR* taskdirptr = opendir(taskdir);
struct dirent* ent = NULL;
pid_t threadpid;
char* dname;
while (NULL != (ent = readdir(taskdirptr))) {
if (0 == strcmp(ent->d_name, mypid) ||
0 == strcmp(ent->d_name, ".") ||
0 == strcmp(ent->d_name, "..")) {
continue;
}
break;
}
dname = ent->d_name;
threadpid = (pthread_t) atoi(dname);
printf("Killing %ld\n", (long) threadpid);
kill(threadpid, 9);
printf("OK, test passed\n");
}
** Also affects: linux
Importance: Undecided
Status: New
--
kill(2) succeeds when no process corresponds to the given PID
https://bugs.launchpad.net/bugs/341239
You received this bug notification because you are a member of Kernel
Bugs, which is subscribed to Linux.
More information about the kernel-bugs
mailing list