2 /*******************************************************************************
3 * The BYTE UNIX Benchmarks - Release 3
4 * Module: context1.c SID: 3.3 5/15/91 19:30:18
6 *******************************************************************************
7 * Bug reports, patches, comments, suggestions should be sent to:
9 * Ben Smith, Rick Grehan or Tom Yager
10 * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
12 *******************************************************************************
14 * $Header: context1.c,v 3.4 87/06/22 14:22:59 kjmcdonell Beta $
15 * August 28, 1990 - changed timing routines--now returns total number of
16 * iterations in specified time period
17 * October 22, 1997 - code cleanup to remove ANSI C compiler warnings
18 * Andy Kahn <kahn@zk3.dec.com>
20 ******************************************************************************/
21 char SCCSid
[] = "@(#) @(#)context1.c:3.3 -- 5/15/91 19:30:18";
23 * Context switching via synchronized unbuffered pipe i/o
31 #include <sys/types.h>
45 fprintf(stderr
, "COUNT|%lu|1|lps\n", iter
);
52 int main(int argc
, char *argv
[])
59 fprintf(stderr
, "Usage: context duration\n");
63 duration
= atoi(argv
[1]);
65 /* set up alarm call */
67 wake_me(duration
, report
);
69 if (pipe(p1
) || pipe(p2
)) {
70 perror("pipe create failed");
75 if (fork()) { /* parent process */
77 if ((child
= fork())) {
79 /* master, write p1 & read p2 */
80 close(p1
[0]); close(p2
[1]);
82 if (write(p1
[1], (char *)&iter
, sizeof(iter
)) != sizeof(iter
)) {
83 if ((errno
!= 0) && (errno
!= EINTR
))
84 perror("master write failed");
87 if (read(p2
[0], (char *)&check
, sizeof(check
)) != sizeof(check
)) {
88 if ((errno
!= 0) && (errno
!= EINTR
))
89 perror("master read failed");
93 fprintf(stderr
, "Master sync error: expect %lu, got %lu\n",
100 else { /* child process */
104 /* slave, read p1 & write p2 */
105 close(p1
[1]); close(p2
[0]);
107 if (read(p1
[0], (char *)&check
, sizeof(check
)) != sizeof(check
)) {
108 if ((errno
!= 0) && (errno
!= EINTR
))
109 perror("slave read failed");
112 if (check
!= iter1
) {
113 fprintf(stderr
, "Slave sync error: expect %lu, got %lu\n",
117 if (write(p2
[1], (char *)&iter1
, sizeof(iter1
)) != sizeof(check
)) {
118 if ((errno
!= 0) && (errno
!= EINTR
))
119 perror("slave write failed");