diff --git a/tools/test/stress2/misc/callout_reset_on.sh b/tools/test/stress2/misc/callout_reset_on.sh index cdffc0dd67f7..bafeeea270c7 100755 --- a/tools/test/stress2/misc/callout_reset_on.sh +++ b/tools/test/stress2/misc/callout_reset_on.sh @@ -1,331 +1,329 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Scenario based on pr. kern/166340 # Process under FreeBSD 9.0 hangs in uninterruptable sleep with apparently # no syscall (empty wchan). # http://people.freebsd.org/~pho/stress/log/callout_reset_on.txt # Fixed in r243901. # panic: Bad link elm 0xfffff80012ba8ec8 prev->next != elm # https://people.freebsd.org/~pho/stress/log/rrs005.txt # Fixed in r278623. # "ritwait DE 0- 0:00.01 crlogger: writer" seen. # https://people.freebsd.org/~pho/stress/log/kostik917.txt # Fixed in r302981 . ../default.cfg rm -f /tmp/crwriter /tmp/crlogger || exit 1 cat > /tmp/crwriter.c < #include #include #include char *txt[] = { "0 This is a line of text: abcdefghijklmnopqrstuvwxyz", "1 Another line of text: ABCDEFGHIJKLMNOPQRSTUVWXYZ", "2 A different line of text", "3 A very, very different text", "4 A much longer line with a lot of characters in the line", "5 Now this is a quite long line of text, with both upper and lower case letters, and one digit!" }; int main(void) { int i, j, n; char help[256]; for (i = 0; i < 100000; i++) { j = arc4random() % 6; n = arc4random() % strlen(txt[j]); strncpy(help, txt[j], n); help[n] = 0; printf("%s\n", txt[j]); if ((arc4random() % 1000) == 1) usleep(100000); } return (0); } EOF mycc -o /tmp/crwriter -Wall -Wextra -O2 -g /tmp/crwriter.c rm -f /tmp/crwriter.c cat > /tmp/crlogger.c < #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define BARRIER_CREATE 1 #define BARRIER_WAIT 2 #define BARRIER_DELETE 3 void barrier(int mode) { int fd; char path[128]; if (mode == BARRIER_CREATE) { snprintf(path, sizeof(path), "barrier.%d", getpid()); if ((fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) err(1, "%s", path); } else if (mode == BARRIER_WAIT) { snprintf(path, sizeof(path), "barrier.%d", getppid()); for(;;) { if (access(path, R_OK) == -1) break; usleep(10000); } } else if (mode == BARRIER_DELETE) { snprintf(path, sizeof(path), "barrier.%d", getpid()); if (unlink(path) == -1) err(1, "unlink(%s)", path); } else errx(1, "Bad barrier mode: %d", mode); } pid_t pid; int bufsize; int port; int alarm_exit; void killer(void) { setproctitle("killer"); alarm(120); barrier(BARRIER_WAIT); for (;;) { if (pid == 0) break; if (kill(pid, SIGUSR1) == -1) break; usleep(1000); } _exit(0); } void handler(int s __unused) { } void ahandler(int s __unused) { if (alarm_exit) _exit(0); } /* Read form socket, discard */ static void reader(void) { int tcpsock, msgsock; int on; socklen_t len; struct sockaddr_in inetaddr, inetpeer; int n, *buf; setproctitle("reader - init"); on = 1; if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); signal(SIGUSR1, handler); alarm(60); if (bind(tcpsock, (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) err(1, "bind(), %s:%d", __FILE__, __LINE__); if (listen(tcpsock, 5) < 0) err(1, "listen(), %s:%d", __FILE__, __LINE__); len = sizeof(inetpeer); if ((msgsock = accept(tcpsock, (struct sockaddr *)&inetpeer, &len)) < 0) err(1, "accept(), %s:%d", __FILE__, __LINE__); if ((buf = malloc(bufsize)) == NULL) err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); setproctitle("reader"); alarm(0); signal(SIGALRM, ahandler); for (;;) { ualarm(5000, 0); if ((n = recvfrom(msgsock, buf, 4, 0, NULL, NULL)) < 0) { if (errno == EAGAIN) continue; err(1, "read(), %s:%d", __FILE__, __LINE__); } if (n == 0) break; if (write(msgsock, "OK", 3) != 3) err(1, "write ack. %s:%d", __FILE__, __LINE__); } close(msgsock); _exit(0); } /* read from stdin, write to socket */ static void writer(void) { int tcpsock, on; struct sockaddr_in inetaddr; struct hostent *hostent; int i, r; char line[1024], ack[80];; - pid_t ppid; setproctitle("writer - init"); - ppid = getppid(); signal(SIGUSR1, handler); alarm(60); on = 1; for (i = 1; i < 5; i++) { if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); hostent = gethostbyname ("localhost"); bzero(&inetaddr, sizeof(inetaddr)); memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); inetaddr.sin_family = AF_INET; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); r = connect(tcpsock, (struct sockaddr *) &inetaddr, sizeof(inetaddr)); if (r == 0) break; sleep(1); close(tcpsock); } if (r < 0) err(1, "connect(), %s:%d", __FILE__, __LINE__); setproctitle("writer"); barrier(BARRIER_DELETE); alarm(0); while (fgets(line, sizeof(line), stdin) != NULL) { alarm(10); alarm_exit = 1; if (write(tcpsock, line, strlen(line)) < 0) err(1, "socket write(). %s:%d", __FILE__, __LINE__); alarm_exit = 0; ualarm(5000, 0); if (recvfrom(tcpsock, ack, 4, 0, NULL, NULL) < 0) { if (errno == EAGAIN) continue; err(1, "read(), %s:%d", __FILE__, __LINE__); } } sleep(30); return; } int main(int argc, char **argv) { pid_t kpid; if (argc != 2) errx(1, "Usage: %s \n", argv[0]); port = atoi(argv[1]); bufsize = 128; barrier(BARRIER_CREATE); signal(SIGCHLD, SIG_IGN); if ((pid = fork()) == 0) reader(); if ((kpid = fork()) == 0) killer(); writer(); sleep(1); kill(pid, SIGINT); kill(kpid, SIGINT); return (0); } EOF mycc -o /tmp/crlogger -Wall -Wextra -O2 -g /tmp/crlogger.c rm -f /tmp/crlogger.c N=200 cd /tmp start=`date '+%s'` for i in `jot 40`; do for j in `jot $N`; do /tmp/crwriter | /tmp/crlogger 1236$j 2>/dev/null & done for j in `jot $N`; do wait done [ $((`date '+%s'` - start)) -gt 1200 ] && break done rm -f /tmp/crwriter /tmp/crlogger ./barrier.* exit 0 diff --git a/tools/test/stress2/misc/callout_reset_on2.sh b/tools/test/stress2/misc/callout_reset_on2.sh index 270aeb95aa97..1a54097ff4ba 100755 --- a/tools/test/stress2/misc/callout_reset_on2.sh +++ b/tools/test/stress2/misc/callout_reset_on2.sh @@ -1,303 +1,301 @@ #!/bin/sh # # Copyright (c) 2012 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Copy of callout_reset_on.sh. Waiting to see if this catches anything. . ../default.cfg rm -f /tmp/crwriter2 /tmp/crlogger2 || exit 1 cat > /tmp/crwriter2.c < #include #include #include #include char *txt[] = { "0 This is a line of text: abcdefghijklmnopqrstuvwxyz", "1 Another line of text: ABCDEFGHIJKLMNOPQRSTUVWXYZ", "2 A different line of text", "3 A very, very different text", "4 A much longer line with a lot of characters in the line", "5 Now this is a quite long line of text, with both upper and lower case letters, and one digit!" }; #define RUNTIME (10 * 60) int main(void) { time_t start; int j, n; char help[256]; start = time(NULL); while (time(NULL) - start < RUNTIME) { j = arc4random() % 6; n = arc4random() % strlen(txt[j]); strncpy(help, txt[j], n); help[n] = 0; printf("%s\n", txt[j]); if ((arc4random() % 1000) == 1) usleep(100000); } return (0); } EOF mycc -o /tmp/crwriter2 -Wall -Wextra -O2 -g /tmp/crwriter2.c rm -f /tmp/crwriter2.c cat > /tmp/crlogger2.c < #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include volatile u_int *share; #define SYNC 0 pid_t pid; int bufsize; int port; int alarm_exit; void killer(void) { setproctitle("killer"); while (share[SYNC] == 0) ; alarm(120); for (;;) { if (pid == 0) break; if (kill(pid, SIGUSR1) == -1) break; usleep(arc4random() % 2000 + 10); } _exit(0); } void handler(int s __unused) { } void ahandler(int s __unused) { if (alarm_exit) _exit(0); } /* Read form socket, discard */ static void reader(void) { int tcpsock, msgsock; int on; socklen_t len; struct sockaddr_in inetaddr, inetpeer; int n, *buf; setproctitle("reader - init"); on = 1; if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); inetaddr.sin_family = AF_INET; inetaddr.sin_addr.s_addr = INADDR_ANY; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); signal(SIGUSR1, handler); alarm(60); if (bind(tcpsock, (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0) err(1, "bind(), %s:%d", __FILE__, __LINE__); if (listen(tcpsock, 5) < 0) err(1, "listen(), %s:%d", __FILE__, __LINE__); len = sizeof(inetpeer); if ((msgsock = accept(tcpsock, (struct sockaddr *)&inetpeer, &len)) < 0) err(1, "accept(), %s:%d", __FILE__, __LINE__); if ((buf = malloc(bufsize)) == NULL) err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__); setproctitle("reader"); alarm(0); signal(SIGALRM, ahandler); for (;;) { ualarm(arc4random() % 5000 + 100, 0); if ((n = recvfrom(msgsock, buf, bufsize, 0, NULL, NULL)) < 0) { if (errno == EAGAIN) continue; err(1, "read(), %s:%d", __FILE__, __LINE__); } if (n == 0) break; if (write(msgsock, "OK", 3) != 3) err(1, "write ack. %s:%d", __FILE__, __LINE__); } close(msgsock); _exit(0); } /* read from stdin, write to socket */ static void writer(void) { int tcpsock, on; struct sockaddr_in inetaddr; struct hostent *hostent; int i, r; char line[1024], ack[80];; - pid_t ppid; setproctitle("writer - init"); share[SYNC] = 1; - ppid = getppid(); signal(SIGUSR1, handler); signal(SIGALRM, ahandler); alarm(60); on = 1; for (i = 1; i < 5; i++) { if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) err(1, "socket(), %s:%d", __FILE__, __LINE__); if (setsockopt(tcpsock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) err(1, "setsockopt(), %s:%d", __FILE__, __LINE__); hostent = gethostbyname ("localhost"); bzero(&inetaddr, sizeof(inetaddr)); memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); inetaddr.sin_family = AF_INET; inetaddr.sin_port = htons(port); inetaddr.sin_len = sizeof(inetaddr); r = connect(tcpsock, (struct sockaddr *) &inetaddr, sizeof(inetaddr)); if (r == 0) break; sleep(1); close(tcpsock); } if (r < 0) err(1, "connect(), %s:%d", __FILE__, __LINE__); setproctitle("writer"); alarm(0); while (fgets(line, sizeof(line), stdin) != NULL) { alarm(10); alarm_exit = 1; if (write(tcpsock, line, strlen(line)) < 0) err(1, "socket write(). %s:%d", __FILE__, __LINE__); alarm_exit = 0; ualarm(arc4random() % 5000 + 1000, 0); if (recvfrom(tcpsock, ack, 4, 0, NULL, NULL) < 0) { if (errno == EAGAIN) continue; err(1, "read(), %s:%d", __FILE__, __LINE__); } } sleep(30); return; } int main(int argc, char **argv) { pid_t kpid; size_t len; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); _exit(1); } port = atoi(argv[1]); bufsize = 128; len = PAGE_SIZE; if ((share = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED) err(1, "mmap"); signal(SIGCHLD, SIG_IGN); if ((pid = fork()) == 0) reader(); if ((kpid = fork()) == 0) killer(); writer(); sleep(1); kill(pid, SIGINT); kill(kpid, SIGINT); return (0); } EOF mycc -o /tmp/crlogger2 -Wall -Wextra -O2 -g /tmp/crlogger2.c rm -f /tmp/crlogger2.c N=50 cd /tmp for j in `jot $N`; do /tmp/crwriter2 | /tmp/crlogger2 1236$j & done wait rm -f /tmp/crwriter2 /tmp/crlogger2 exit 0 diff --git a/tools/test/stress2/misc/datamove3.sh b/tools/test/stress2/misc/datamove3.sh index 47a1cbce4c95..19beffc00655 100755 --- a/tools/test/stress2/misc/datamove3.sh +++ b/tools/test/stress2/misc/datamove3.sh @@ -1,241 +1,241 @@ #!/bin/sh # # Copyright (c) 2009 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # Threaded variation of datamove.sh # Based on a test scenario by ups and suggestions by kib [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg here=`pwd` cd /tmp sed '1,/^EOF/d' < $here/$0 > datamove3.c mycc -o datamove3 -Wall datamove3.c -lpthread rm -f datamove3.c n=5 old=`sysctl vm.old_msync | awk '{print $NF}'` sysctl vm.old_msync=1 for i in `jot $n`; do mkdir -p /tmp/datamove3.dir.$i cd /tmp/datamove3.dir.$i /tmp/datamove3 & done cd /tmp for i in `jot $n`; do wait done for i in `jot $n`; do rm -rf /tmp/datamove3.dir.$i done sysctl vm.old_msync=$old rm -rf /tmp/datamove3 exit 0 EOF /*- * Copyright (c) 2006, Stephan Uphoff * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice unmodified, this list of conditions, and the following * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include struct args { char *bp; int fd1; int fd2; } a[2]; int prepareFile(char *, int *); void * mapBuffer(void *); int startIO(int, char *); int pagesize; #define FILESIZE (32*1024) char wbuffer [FILESIZE]; /* Create a FILESIZE sized file - then remove file data from the cache */ int prepareFile(char *filename, int *fdp) { int fd; int len; int status; void *addr; fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU); if (fd == -1) { perror("Creating file"); return fd; } len = write(fd, wbuffer, FILESIZE); if (len < 0) { perror("Write failed"); return 1; } status = fsync(fd); if (status != 0) { perror("fsync failed"); return 1; } addr = mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { perror("Mmap failed"); return 1; } status = msync(addr, FILESIZE, MS_INVALIDATE | MS_SYNC); if (status != 0) { perror("Msync failed"); return 1; } munmap(addr, FILESIZE); *fdp = fd; return 0; } /* mmap a 2 page buffer - first page is from fd1, second page from fd2 */ void * mapBuffer(void *ar) { void *addr; char *buffer; int i; - i = (int )ar; + i = (intptr_t)ar; addr = mmap(NULL, pagesize * 2, PROT_READ | PROT_WRITE, MAP_SHARED, a[i].fd1, 0); if (addr == MAP_FAILED) { err(1, "Mmap failed"); } buffer = addr; addr = mmap(buffer + pagesize, pagesize, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, a[i].fd2, 0); if (addr == MAP_FAILED) { err(1, "Mmap2 failed"); } a[i].bp = buffer; sleep(1); return (NULL); } int startIO(int fd, char *buffer) { ssize_t len; len = write(fd, buffer, 2 * pagesize); if (len == -1) { warn("startIO(%d, %p): write failed", fd, buffer); return 1; } return 0; } int main(int argc, char *argv[], char *envp[]) { int fdA, fdB, fdDelayA, fdDelayB; int r, status; char *bufferA, *bufferB; pid_t pid; pthread_t threads[2]; pagesize = getpagesize(); if ((prepareFile("A", &fdA)) || (prepareFile("B", &fdB)) || (prepareFile("DelayA", &fdDelayA)) || (prepareFile("DelayB", &fdDelayB))) exit(1); a[0].fd1 = fdDelayA; a[0].fd2 = fdB; a[1].fd1 = fdDelayB; a[1].fd2 = fdA; if ((r = pthread_create(&threads[0], NULL, mapBuffer, (void *)0)) != 0) errc(1, r, "pthread_create()"); if ((r = pthread_create(&threads[1], NULL, mapBuffer, (void *)1)) != 0) errc(1, r, "pthread_create()"); while (a[0].bp == NULL || a[1].bp == NULL) pthread_yield(); bufferA = a[0].bp; bufferB = a[1].bp; pid = fork(); if (pid == 0) { status = startIO(fdA, bufferA); exit(status); } if (pid == -1) { exit(1); } status = startIO(fdB, bufferB); exit(status); }