00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/pipe_tests.c,v 1.4 2004/05/07 10:20:09 merzky Exp $";
00018
00019
00020
00021 #include <limits.h>
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <unistd.h>
00025 #include <sys/types.h>
00026 #include <sys/wait.h>
00027
00028
00029
00030 #include "GAT.h"
00031 #include "GATTestUtils.h"
00032
00033
00034 #if !defined(MAX_PATH)
00035 # define MAX_PATH _POSIX_PATH_MAX
00036 #endif
00037
00038
00039
00040
00041
00042
00043 static int execute_pipe_read_client(void);
00044 static int execute_pipe_write_client(void);
00045
00046
00047
00048
00049
00050 int main(int argc, const char * const argv[])
00051 {
00052 int read_pid = 0;
00053 int write_pid = 0;
00054 int status = 0;
00055
00056 read_pid = execute_pipe_read_client();
00057 sleep(2);
00058 write_pid = execute_pipe_write_client();
00059
00060
00061 waitpid(write_pid, &status, 0);
00062
00063
00064 waitpid(read_pid, &status, 0);
00065
00066 return 0;
00067 }
00068
00069
00070 static int
00071 execute_pipe_read_client(void)
00072 {
00073 #if !defined(WIN32)
00074 pid_t pid = 0;
00075 if ( (pid = fork()) < 0)
00076 {
00077 perror("fork: pipe_read_tests");
00078 }
00079 else if (0 == pid)
00080 {
00081 char exe[MAX_PATH];
00082 snprintf (exe, MAX_PATH-1, "%s/bin/tests/pipe_read_tests", getenv ("GAT_LOCATION"));
00083
00084 if (execlp(exe, "pipe_read_tests", NULL) < 0)
00085 {
00086 perror ("execlp: pipe_read_tests");
00087 fprintf (stderr, "expecting pipe_read_tests in $GAT_LOCATION/bin/tests/\n");
00088 }
00089 }
00090 return pid;
00091 #else
00092 return _spawnl(_P_NOWAIT, "pipe_read_tests.exe", "pipe_read_tests.exe", NULL);
00093 #endif
00094 }
00095
00096 static int
00097 execute_pipe_write_client(void)
00098 {
00099 #if !defined(WIN32)
00100 pid_t pid = 0;
00101 if ( (pid = fork()) < 0)
00102 {
00103 perror("fork: pipe_write_tests");
00104 }
00105 else if (0 == pid)
00106 {
00107 char exe[MAX_PATH];
00108 snprintf (exe, MAX_PATH-1, "%s/bin/tests/pipe_write_tests", getenv ("GAT_LOCATION"));
00109
00110 if (execlp(exe, "pipe_write_tests", NULL) < 0)
00111 {
00112 perror ("execlp: pipe_write_tests");
00113 fprintf (stderr, "expecting pipe_write_tests in $GAT_LOCATION/bin/tests/\n");
00114 }
00115 }
00116 return pid;
00117 #else
00118 return _spawnl(_P_NOWAIT, "pipe_write_tests.exe", "pipe_write_tests.exe", NULL);
00119 #endif
00120 }
00121