首页 文章

C中的共享内存与LinkedList

提问于
浏览
1

我必须在C中开发一个迷你shell . 在这个项目中,我们必须处理局部变量和环境变量 . 所以我们可以有两个共享环境变量的进程,在父进程中可以看到一个变量创建,反之亦然 .

我的老师说: The environment variables are stored in a shared memory area that is created by the first copy of your shell that runs and is initialized with all the variables defined in the envp array. The last copy of your shell that runs at any given time must destroy that space. This shared memory area is to be managed as a memory by subdivision. The shared memory area is a concurrent access memory area with multiple possible simultaneous reads but only 1 write possible at a given time. Implementation must give priority to writing.

所以我们需要包含链接列表的共享内存:

  • 变量名称(char *)

  • 由shmget()返回的int

  • 和一个char *由shmat()返回,变量的值

但是当我们在父亲中创建一个环境变量时,孩子就没有 .

所以我认为这种方法不正确,我们怎么能代表这个问题呢?

也许不使用链表?

谢谢 .

TF .

1 回答

  • 1

    我明白 !我老师说我要创建一个固定大小的共享内存空间!现在很简单 .

    谢谢大家 .

相关问题