#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "structs.h"
#include "server.h"
#include "client.h"
int main(void)
{
pid_t pid;
int mypipe[2];
int otherPipe[2];
if(pipe(mypipe))
{
printf("Error in making a pipe");
}
if(pipe(otherPipe))
{
printf("Error creating another pipe");
}
if((pid=fork()) == -1)
{
perror("fork");
exit(1);
}
printf("Child ID: %d" , pid);
if(pid == 0)
{
close(mypipe[1]);
close(otherPipe[0]);
client *c = new client(mypipe[0], otherPipe[1]);
wait(NULL);
//c->startProgram();
//return EXIT_SUCCESS;
}
else
{
printf("Yo");
close(mypipe[0]);
close(otherPipe[1]);
server s;
s.fdIn = otherPipe[0];
s.fdOut = mypipe[1];
s.startServer();
//wait(NULL);
//return EXIT_SUCCESS;
}
}
以上是我的代码。子进程运行良好(如果我明显删除了该评论),但是 else 永远不会被执行(或者我在终端中遗漏了什么?)。
这是输出的屏幕截图:http: //i.imgur.com/dUWn8.png
关于为什么它不去其他/父母地点的任何想法?
谢谢!