public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* manpages: explicit set SIGCHLD to SIG_IGN is distinct from SIG_DFL
@ 2008-04-07 16:16 Justin Pryzby
  2008-04-07 21:04 ` Michael Kerrisk
  0 siblings, 1 reply; 4+ messages in thread
From: Justin Pryzby @ 2008-04-07 16:16 UTC (permalink / raw)
  To: linux-man-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 1202 bytes --]

Version: 2.79-2
File: /usr/share/man/man2/wait.2.gz

What do people think of something like the attached change?  While
working with Debian's cron package, I found that explicitly setting
the SIGCHLD action to SIG_IGN inhibits the creation of zombie
processes, even though kill(1) gives the "ignore" as the default
disposition.

Consider the attached example program.  Any of the following changes
will cause a zombie process to be visible in a ps -ef process listing:

 . remove the call to signal();
 . change SIG_IGN to SIG_DFL;
 . remove the sleep(1); (due to process scheduling, the zombie is only
   sometimes visible);
 . ???

--- /usr/share/man/man2/wait.2.gz
+++ /tmp/wait2.gz.22000	2008-04-07 12:02:31.000000000 -0400
@@ -46,7 +46,7 @@
 .\"	Much other text rewritten
 .\" 2005-05-10, mtk, __W* flags can't be used with waitid()
 .\"
-.TH WAIT 2  2007-07-26 "Linux" "Linux Programmer's Manual"
+.TH WAIT 2  2008-04-07 "Linux" "Linux Programmer's Manual"
 .SH NAME
 wait, waitpid, waitid \- wait for process to change state
 .SH SYNOPSIS
@@ -429,7 +429,7 @@
 
 POSIX.1-2001 specifies that if the disposition of
 .B SIGCHLD
-is set to
+is set explicitly to
 .B SIG_IGN
 or the
 .B SA_NOCLDWAIT


[-- Attachment #2: sig.c --]
[-- Type: text/x-csrc, Size: 1752 bytes --]

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#include <sys/types.h>
#include <sys/wait.h>

int main()
{
	int status;
	void *ret;
	pid_t pid, p2;

	int pp[2];
	if (pipe(pp)) {
		perror("pipe");
		exit(EXIT_FAILURE);
	}

	switch (pid=fork()) {
	case -1:
		perror("fork");
		exit(EXIT_FAILURE);
	case 0:	// Child
		close(pp[0]);
		switch (pid=fork()) {
		case -1:
			perror("fork");
			exit(EXIT_FAILURE);
		case 0:	// Child
			sleep(10);
			break;
		default:
			exit(EXIT_SUCCESS);
		}
		exit(EXIT_SUCCESS);
	default: // Parent
		close(pp[1]);

		ret=signal(SIGCHLD, SIG_IGN);
		if (ret==SIG_ERR) {
			perror("signal");
		} else if (ret==SIG_IGN) {
			fputs("was: sig_ign\n", stderr);
		} else if (ret==SIG_DFL) {
			fputs("was: sig_dfl\n", stderr);
		} else {
			fputs("unknown initial signal handler\n", stderr);
		}

		break;
	}

	sleep(1);
	for ( ; 1; ) {
		char buf;
		switch (read(pp[0], &buf, sizeof buf)) {
			case 0:	// EOF
				exit(EXIT_SUCCESS);
			case -1:
				perror("read");
				exit(EXIT_FAILURE);
			case 1:
				continue;
		}
	}

	for ( ; 1; ) {
		p2=waitpid(pid, &status, WUNTRACED);
		if (p2==-1) {
			if (errno==ECHILD) break;
			perror("wait");
			exit(EXIT_FAILURE);
		}

		if (WIFEXITED(status)) {
			status=WEXITSTATUS(status);
			if (status==0) {
				puts("Exited successfully");
			} else {
				printf("Exited with status: %d\n", status);
			}
		} else if (WIFSIGNALED(status)) {
#ifndef	WCOREDUMP
#define	WCOREDUMP 0
#endif
			printf("Killed by signal: %d%s\n", WTERMSIG(status),
					WCOREDUMP(status)?"; dumped core":"");
		} else if (WIFSTOPPED(status)) {
			status=WSTOPSIG(status);
			printf("Stopped by signal: %d\n", status);
			// kill(getpid(), status);
		}
	}

	exit(EXIT_SUCCESS);
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: manpages: explicit set SIGCHLD to SIG_IGN is distinct from SIG_DFL
  2008-04-07 16:16 manpages: explicit set SIGCHLD to SIG_IGN is distinct from SIG_DFL Justin Pryzby
@ 2008-04-07 21:04 ` Michael Kerrisk
       [not found]   ` <cfd18e0f0804071404j630a631ev6991dfff67fc406e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Kerrisk @ 2008-04-07 21:04 UTC (permalink / raw)
  To: Justin Pryzby; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

On Mon, Apr 7, 2008 at 6:16 PM, Justin Pryzby
<justinpryzby-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org> wrote:
> Version: 2.79-2
> File: /usr/share/man/man2/wait.2.gz
>
> What do people think of something like the attached change?  While
> working with Debian's cron package, I found that explicitly setting
> the SIGCHLD action to SIG_IGN inhibits the creation of zombie
> processes, even though kill(1) gives the "ignore" as the default
> disposition.
>
> Consider the attached example program.  Any of the following changes
> will cause a zombie process to be visible in a ps -ef process listing:
>
>  . remove the call to signal();
>  . change SIG_IGN to SIG_DFL;
>  . remove the sleep(1); (due to process scheduling, the zombie is only
>   sometimes visible);
>  . ???
>
> --- /usr/share/man/man2/wait.2.gz
> +++ /tmp/wait2.gz.22000 2008-04-07 12:02:31.000000000 -0400
> @@ -46,7 +46,7 @@
>  .\"    Much other text rewritten
>  .\" 2005-05-10, mtk, __W* flags can't be used with waitid()
>  .\"
> -.TH WAIT 2  2007-07-26 "Linux" "Linux Programmer's Manual"
> +.TH WAIT 2  2008-04-07 "Linux" "Linux Programmer's Manual"
>  .SH NAME
>  wait, waitpid, waitid \- wait for process to change state
>  .SH SYNOPSIS
> @@ -429,7 +429,7 @@
>
>  POSIX.1-2001 specifies that if the disposition of
>  .B SIGCHLD
> -is set to
> +is set explicitly to
>  .B SIG_IGN
>  or the
>  .B SA_NOCLDWAIT

I would not favor this.  It suggests that there is the notion of
"implicitly" setting the disposition to SIG_IGN, which of course there
isn't.  What I've instead done is added a sentence:

    Note that even though

-- 
Michael Kerrisk
Maintainer of the Linux man-pages project
http://www.kernel.org/doc/man-pages/
Want to report a man-pages bug? Look here:
http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: manpages: explicit set SIGCHLD to SIG_IGN is distinct from SIG_DFL
       [not found]   ` <cfd18e0f0804071404j630a631ev6991dfff67fc406e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2008-04-07 21:08     ` Michael Kerrisk
       [not found]       ` <cfd18e0f0804071408k6a559321xd80a792f62879d81-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Kerrisk @ 2008-04-07 21:08 UTC (permalink / raw)
  To: Justin Pryzby; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

On Mon, Apr 7, 2008 at 11:04 PM, Michael Kerrisk
<mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
>
> On Mon, Apr 7, 2008 at 6:16 PM, Justin Pryzby
> <justinpryzby-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org> wrote:
> > Version: 2.79-2
> > File: /usr/share/man/man2/wait.2.gz
> >
> > What do people think of something like the attached change?  While
> > working with Debian's cron package, I found that explicitly setting
> > the SIGCHLD action to SIG_IGN inhibits the creation of zombie
> > processes, even though kill(1) gives the "ignore" as the default
> > disposition.
> >
> > Consider the attached example program.  Any of the following changes
> > will cause a zombie process to be visible in a ps -ef process listing:
> >
> >  . remove the call to signal();
> >  . change SIG_IGN to SIG_DFL;
> >  . remove the sleep(1); (due to process scheduling, the zombie is only
> >   sometimes visible);
> >  . ???
> >
> > --- /usr/share/man/man2/wait.2.gz
> > +++ /tmp/wait2.gz.22000 2008-04-07 12:02:31.000000000 -0400
> > @@ -46,7 +46,7 @@
> >  .\"    Much other text rewritten
> >  .\" 2005-05-10, mtk, __W* flags can't be used with waitid()
> >  .\"
> > -.TH WAIT 2  2007-07-26 "Linux" "Linux Programmer's Manual"
> > +.TH WAIT 2  2008-04-07 "Linux" "Linux Programmer's Manual"
> >  .SH NAME
> >  wait, waitpid, waitid \- wait for process to change state
> >  .SH SYNOPSIS
> > @@ -429,7 +429,7 @@
> >
> >  POSIX.1-2001 specifies that if the disposition of
> >  .B SIGCHLD
> > -is set to
> > +is set explicitly to
> >  .B SIG_IGN
> >  or the
> >  .B SA_NOCLDWAIT
>
> I would not favor this.  It suggests that there is the notion of
> "implicitly" setting the disposition to SIG_IGN, which of course there
> isn't.  What I've instead done is added a sentence:
>
>    Note that even though

Ooops -- I accidentally sent an incomplete draft.

The sentence I added was:

    Note that even though the default disposition of SIGCHLD is
"ignore", explicitly
    setting the disposition to SIG_IGN results in different treatement of zombie
    children.

Seem okay?

Cheers,

Michael
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: manpages: explicit set SIGCHLD to SIG_IGN is distinct from SIG_DFL
       [not found]       ` <cfd18e0f0804071408k6a559321xd80a792f62879d81-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2008-04-07 21:20         ` Justin Pryzby
  0 siblings, 0 replies; 4+ messages in thread
From: Justin Pryzby @ 2008-04-07 21:20 UTC (permalink / raw)
  To: linux-man-u79uwXL29TY76Z2rM5mHXA

On Mon, Apr 07, 2008 at 11:08:02PM +0200, Michael Kerrisk wrote:
> On Mon, Apr 7, 2008 at 11:04 PM, Michael Kerrisk
> <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
> >
> > On Mon, Apr 7, 2008 at 6:16 PM, Justin Pryzby
> > <justinpryzby-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org> wrote:
> > > Version: 2.79-2
> > > File: /usr/share/man/man2/wait.2.gz
> > >
> > > the SIGCHLD action to SIG_IGN inhibits the creation of zombie
> > > processes, even though kill(1) gives the "ignore" as the default
> > > disposition.

>     Note that even though the default disposition of SIGCHLD is
>     "ignore", explicitly setting the disposition to SIG_IGN results
>     in different treatement of zombie children.
> 
> Seem okay?
Yup.

Thanks,
Justin
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-04-07 21:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-07 16:16 manpages: explicit set SIGCHLD to SIG_IGN is distinct from SIG_DFL Justin Pryzby
2008-04-07 21:04 ` Michael Kerrisk
     [not found]   ` <cfd18e0f0804071404j630a631ev6991dfff67fc406e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-04-07 21:08     ` Michael Kerrisk
     [not found]       ` <cfd18e0f0804071408k6a559321xd80a792f62879d81-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-04-07 21:20         ` Justin Pryzby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox