LKML Archive on
help / color / mirror / Atom feed
* [PATCH 3/3] exit_notify: fix kill_orphaned_pgrp() usage with mt exit
@ 2008-03-02 18:44 Oleg Nesterov
  0 siblings, 0 replies; only message in thread
From: Oleg Nesterov @ 2008-03-02 18:44 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Alan Cox, Davide Libenzi, Eric W. Biederman, Ingo Molnar,
	Linus Torvalds, Roland McGrath, linux-kernel

1. exit_notify() always calls kill_orphaned_pgrp(). This is wrong, we
   should do this only when the whole process exits.

2. exit_notify() uses "current" as "ignored_task", obviously wrong.
   Use ->group_leader instead.

Test case:

	void hup(int sig)
		printf("HUP received\n");

	void *tfunc(void *arg)
		printf("sub-thread exited\n");
		return NULL;

	int main(int argc, char *argv[])
		if (!fork()) {
			signal(SIGHUP, hup);
			kill(getpid(), SIGSTOP);

		pthread_t thr;
		pthread_create(&thr, NULL, tfunc, NULL);

		printf("main thread exited\n");
		syscall(__NR_exit, 0);

		return 0;


	main thread exited
	HUP received

With this patch the output is:

	main thread exited
	sub-thread exited
	HUP received

Signed-off-by: Oleg Nesterov <>

--- 25/kernel/exit.c~3_OG_EXIT	2008-03-02 19:42:56.000000000 +0300
+++ 25/kernel/exit.c	2008-03-02 21:21:51.000000000 +0300
@@ -754,7 +754,7 @@ static void forget_original_parent(struc
  * Send signals to all our closest relatives so that they know
  * to properly mourn us..
-static void exit_notify(struct task_struct *tsk)
+static void exit_notify(struct task_struct *tsk, int group_dead)
 	int state;
@@ -770,7 +770,8 @@ static void exit_notify(struct task_stru
-	kill_orphaned_pgrp(tsk, NULL);
+	if (group_dead)
+		kill_orphaned_pgrp(tsk->group_leader, NULL);
 	/* Let father know we died
@@ -985,7 +986,7 @@ NORET_TYPE void do_exit(long code)
-	exit_notify(tsk);
+	exit_notify(tsk, group_dead);
 	tsk->mempolicy = NULL;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-02 18:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-02 18:44 [PATCH 3/3] exit_notify: fix kill_orphaned_pgrp() usage with mt exit Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).