Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where command line arguments are stored?

I have a doubt @ the storage of command line arguments.

myprog.exe -cfgfile myconfig.cfg

commandline args are passed when process gets created so are they strored outside the process?

where OS stores it?

like image 831
Ashish Avatar asked Jan 22 '10 05:01

Ashish


2 Answers

For WIndows, the command line arguments are kept in the process environment block (PEB), which is allocated in the user process address space when the process is created.

You can read Windows Internals for a lot more details. Here's a snippet from Chapter 5 - Processes, Threads, and Jobs.

I would assume that it's the same for the Unix flavors. This data needs to be in the process memory, so that it can be accessed by the process itself.

like image 176
Franci Penov Avatar answered Sep 18 '22 13:09

Franci Penov


It depends on the OS and possibly the language. A good C-centric answer is that the OS creates the process space (including loading the code, creating the heap and stack, etc). Then it puts the command line argument vector in a location, and then copies the address of the argument vector to 'argv' on the stack, and the count of words to 'argc'.

Only after these tasks are done does the OS allow the process to execute.

like image 37
Medivh Avatar answered Sep 18 '22 13:09

Medivh