/* * Copyright (C) 1999, 2001,2005 by Manfred Spraul. * * Redistribution of this file is permitted under the terms of the GNU * General Public License (GPL) * $Header: /home/manfred/cvs-tree/pipetest/test8.cpp,v 1.1 2005/02/05 08:35:01 manfred Exp $ */ #include #include #include #include #include #include #include #include #include #define WRITE_LEN 128 /* less than PIPE_BUF */ int buffer[WRITE_LEN]; void dummy(int sig) { } int main() { int pipes[2]; int ret; ret = pipe(pipes); if(ret != 0) { printf("pipe creation failed, ret %d, errno %d.\n", ret, errno); exit(1); } ret = fork(); if(!ret) { /* child: read from pipe */ printf("child: trying to read %d bytes.\n", WRITE_LEN); ret = read(pipes[0], buffer, WRITE_LEN); /* never executed! */ printf("child: read returned %d.\n", ret); printf("SIGSTOP test result: SIGSTOP completely broken\n"); } else { /* synchronize with timer - the following block must be atomic */ sleep(1); /* begin atomic block */ ret = kill(ret, SIGSTOP); if (ret != 0) { printf("Sending SIGSTOP failed, aborting (errno=%d).\n", errno); exit(1); } ret = write(pipes[1], buffer, WRITE_LEN); if (ret != WRITE_LEN) { printf("Writing to pipe buffer failed, aborting (errno=%d).\n", errno); exit(1); } /* end of atomic block */ printf("parent: yielding\n"); sleep(1); ret = fcntl(pipes[0], F_SETFL, O_NONBLOCK); if (ret != 0) { printf("fcntl(,,O_NONBLOCK) failed, aborting (errno=%d).\n", errno); exit(1); } ret = read(pipes[0], buffer, WRITE_LEN); printf("parent: read returned %d.\n", ret); printf("\n\n"); printf("SIGSTOP test result:\n"); printf("Expected values:\n"); printf(" %d for OS with synchroneous SIGSTOP\n", WRITE_LEN); printf(" -1 for OS with asynchroneous SIGSTOP (errno EAGAIN=%d)\n", EAGAIN); printf("Got: %d (errno: %d)\n", ret, errno); close(pipes[1]); close(pipes[0]); } }