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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With