日期:2014-05-16 浏览次数:20906 次
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <string.h>
char s1[]="1";
char s2[]="1";
int main(int argc, const char * argv[])
{
char buf1[256],a[256]={0},b[256],c[256];
int p1[2],p2[2],p3[2],p4[2];
int parentw1,parentw2, child1r,child2r,parentr1,parentr2,child1w,child2w,pid;
pipe(p1);
pipe(p2);
pipe(p3);
pipe(p4);
child1r=p1[0];
child2r=p2[0];
parentw1=p1[1];
parentw2=p2[1];
parentr1=p3[0];
parentr2=p4[0];
child1w=p3[1];
child2w=p4[1];
if (fork()==0) {
/*first child process--adder*/
pid=getpid();
FILE *fd;
char s[]="stopstop";
close(parentw2);close(parentw1);close(parentr1);close(parentr2);close(child2r);close(child2w);
int f;
int i=0;
int sum=0;
int k[1024];
while (1) {
read(child1r, buf1, sizeof(b)); //get the number of field
f=atoi(buf1);
read(child1r, buf1, sizeof(b)); //get the name of file
sscanf(buf1, "%s",a);
if (strcmp(a,s)==0) //compare to find wether the file name is stopstop if it is ,then break and teminate
{
break;
&nbs