1
votes

I have to develop a mini-shell in C. In this project we have to deal with local variables and environment variables. So we can have two process that shared environment variables, a variable create in the child can be seen in the father and inversely.

My teacher says: 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.

So we need shared memory with linked list who contains:

  • the name of variable (char*)
  • the int return by shmget()
  • and a char* return by shmat(), the value of variable

But when we create a environment variable in the father there is not in the child.

So I think this method is not correct, how can we represents this problem ?

Maybe not use a linked list ?

Thank you.

TF.

1
why shared memory? environment variables already share between parent and child process. - Sumit Gemini
you should know first how command executes on shell. i believe you have to use exec() system call for it. - Sumit Gemini
So you want Inter Process Communication. Wikipedia en.wikipedia.org/wiki/Inter-process_communication has a fair list of options - k_kaz
The shared memory is an obligation because I must create the job of a shell. So I copy the value of envp in my memory shared and I want shared this. I create a new environment variable with internal command setenv (setenv foo=bar). It's a project for my university so I can't use the putenv function for environment variable. But my setenv==putenv for my shell. - Oneill
"shared environment variables" i suggest you double check this. this sounds very similar to, but at the same time different from, how real environment variables behave. as you have stated the task, it is orders of magnitude harder than a simple shell that just uses normal plain environment variables. it would be a shame if you wasted lots of efforts to implement these almost-environment-variables when your teachers meant simple honest real environment variables, and you just misunderstood them. - n. 1.8e9-where's-my-share m.

1 Answers

1
votes

I understand ! My teacher say me to create a shared memory space with fixed size ! It's simple now.

Thank you everyone.