LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 880|回复: 4

进程间的通信

[复制链接]
发表于 2004-3-24 21:03:24 | 显示全部楼层 |阅读模式
关于进程间的通信,请问,我先定义了,几个结构,其中一个结构中有指向另一个结构的指针,就是将这些结构连起来,我现在在子进程中用管道将这个结构传向父进程,可是为什么在父进程中读不到呢?
谢谢,是否还有别的方法。
发表于 2004-3-24 21:20:13 | 显示全部楼层
post your code.
 楼主| 发表于 2004-3-25 08:45:47 | 显示全部楼层
[php]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#define max_vertex_num 20
#define MAX_weight 30
#define NULL 0



/*This defination of the algraph structure*/
typedef struct arcnode{
        int              adjvex;
        struct  arcnode  *nextarc;
        int               weight;
}arcnode;

typedef struct vnode{
        unsigned int data;   /*Record ip_adress  */
        arcnode  *firstarc;
}vnode,adjlist[max_vertex_num];

struct algraph{
        adjlist  vertices;
        int      vexnum,arcnum;
};
int main(void)
{
        struct algraph *g1,g2;
        int fd[2];
        pid_t id;
        pipe(fd);
        g2=(struct algraph *)malloc(sizeof(struct algraph));
        creat_algraph(g);/*生成图的结构函数*/
        if((pid=fork())==-1)
        {
                perror("fork");
                exit(1);
        }else if(pid==0)
                {
                        close(fd[0]);
                        write(fd[1],g1,sizeof(struct algraph));
               
                }
        wait();       
        close(fd[1]);
        read(fd[0],g2,sizeof(struct algraph));/*好像传不过来图中的数据*/       
        print_algraph(g2);/*打印图函数*/
        exit(0);
}
[/php]
谢谢!
发表于 2004-3-25 19:56:46 | 显示全部楼层
有一个错误是明显的。把main()函数中的:

  1. struct algraph *g1,g2;
复制代码

改成:

  1. struct algraph *g1,*g2;
复制代码
 楼主| 发表于 2004-3-26 10:30:48 | 显示全部楼层
那只是一个输入的错误,其实在调的时候已经改了,就是传不过去数据
谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表