* [PATCH] 2.5.5 Fix for get_pid hang
@ 2002-02-22 22:32 Paul Larson
0 siblings, 0 replies; only message in thread
From: Paul Larson @ 2002-02-22 22:32 UTC (permalink / raw)
To: torvalds; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 186 bytes --]
This is a fix for a problem where if we run out of available pids,
get_pid will hang the system while it searches through the tasks for an
available pid forever.
Thanks,
Paul Larson
[-- Attachment #2: getpid25.patch --]
[-- Type: text/x-patch, Size: 1621 bytes --]
diff -Naur linux-2.5.5/kernel/fork.c linux-2.5.5-getpid/kernel/fork.c
--- linux-2.5.5/kernel/fork.c Tue Feb 19 20:10:55 2002
+++ linux-2.5.5-getpid/kernel/fork.c Fri Feb 22 17:29:38 2002
@@ -24,6 +24,7 @@
#include <linux/file.h>
#include <linux/binfmts.h>
#include <linux/fs.h>
+#include <linux/compiler.h>
#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -129,12 +130,13 @@
{
static int next_safe = PID_MAX;
struct task_struct *p;
- int pid;
+ int pid, beginpid;
if (flags & CLONE_PID)
return current->pid;
spin_lock(&lastpid_lock);
+ beginpid = last_pid;
if((++last_pid) & 0xffff8000) {
last_pid = 300; /* Skip daemons etc. */
goto inside;
@@ -154,12 +156,16 @@
last_pid = 300;
next_safe = PID_MAX;
}
+ if(unlikely(last_pid == beginpid))
+ goto nomorepids;
goto repeat;
}
if(p->pid > last_pid && next_safe > p->pid)
next_safe = p->pid;
if(p->pgrp > last_pid && next_safe > p->pgrp)
next_safe = p->pgrp;
+ if(p->tgid > last_pid && next_safe > p->tgid)
+ next_safe = p->tgid;
if(p->session > last_pid && next_safe > p->session)
next_safe = p->session;
}
@@ -169,6 +175,11 @@
spin_unlock(&lastpid_lock);
return pid;
+
+nomorepids:
+ read_unlock(&tasklist_lock);
+ spin_unlock(&lastpid_lock);
+ return 0;
}
static inline int dup_mmap(struct mm_struct * mm)
@@ -667,6 +678,8 @@
copy_flags(clone_flags, p);
p->pid = get_pid(clone_flags);
+ if (p->pid == 0 && current->pid != 0)
+ goto bad_fork_cleanup;
INIT_LIST_HEAD(&p->run_list);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-02-22 22:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-22 22:32 [PATCH] 2.5.5 Fix for get_pid hang Paul Larson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®