kern/158641: Writing > 8192 bytes to a pipe blocks signal handling

Tom Hukins tom at
Mon Jul 4 16:20:09 UTC 2011

>Number:         158641
>Category:       kern
>Synopsis:       Writing > 8192 bytes to a pipe blocks signal handling
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 04 16:20:08 UTC 2011
>Originator:     Tom Hukins
>Release:        FreeBSD 8.2-RELEASE-p2 i386
System: FreeBSD 8.2-RELEASE-p2 FreeBSD 8.2-RELEASE-p2 #0: Wed Jun 15 14:20:45 UTC 2011 root at i386


When a pipe has more than 8192 bytes written to it, the current process
hangs and does not handle signals correctly.


#include <sys/types.h>
#include <sys/uio.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define BUFFER_LENGTH 16384

void catch_alrm(int sig_num) {
    printf("Alarm received\n");

int main (int argc, char **argv) {
    char buff_read[BUFFER_LENGTH];
    int pdes[2];
    if ( pipe(pdes) != 0) {
	return 1;
    signal(SIGALRM, catch_alrm);

    int mypid = getpid();
    write( pdes[1], argv[1], strlen(argv[1]) );
    kill(mypid, SIGALRM);

    return 0;


Save the above as "pipefreeze.c", then run:

% cc -g -Wall pipefreeze.c && ./a.out HELLO
% perl -e 'print q(x) x 8192' | xargs ./a.out &

The first input of < 8192 bytes works fine, the second does not.
Sending "kill -ALRM PID" to the second process in the second example
terminates the process, but does not call the signal handler.





More information about the freebsd-bugs mailing list