【发布时间】:2013-04-01 13:11:06
【问题描述】:
我在弄清楚如何使用我在不同进程之间创建的列表时遇到了麻烦。我有的是:
FileList.h - 我创建的列表
#include "Node.h"
typedef struct FileList {
struct Node *first;
struct Node *last;
int length;
} FileList;
void fl_initialize();
void fl_add(char name[], char up[], bool status);
void fl_edit(Node *n, char up[]);
void fl_remove (char name[]);
int fl_length();
void fl_clear();
void fl_print();
void fl_print_node(Node *n);
void fl_uncheck();
bool fl_clean_unchecked();
Node* fl_get(int pos);
Node* fl_find (char name[]);
在我创建的 FileList.cpp 中
FileList fl;
并实现原型函数。
我将简化我的 main.cpp
#include "FileList.h"
int main (int argc, char *argv[]) {
int r = fork();
if (r == 0) {
fl_initialize();
call_function_that_add_list_elements();
fl_print(); //List contains elements
} else {
waitpid(r, &status, WUNTRACED | WCONTINUED);
if (WIFEXITED(status)) {
fl_print(); //The list is empty (Is other list, probably);
//another_function_that_should_keep_working_with_the_list();
}
}
}
为什么这个列表一旦作为标题包含在内就不是全局的,因此对于父子进程,我怎样才能使其成为全局?
【问题讨论】:
-
stackoverflow.com/questions/9961591/… 应该可以帮助您了解如何在分叉的进程之间共享堆