Where are the command line arguments stored?

I have a doubt about storing command line arguments.

myprog.exe -cfgfile myconfig.cfg

command line arguments are passed when the process is created, so do they go beyond the process?

where does the OS store it?

+4
source share
4 answers

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

You can read Windows Internals for more details. Here is a snippet from Chapter 5 - Processes, Topics, and Tasks .

I would suggest that this is the same for Unix flavors. This data must be in the process memory, so that the process itself can be accessed.

+5
source

It depends on the OS and possibly the language. A good C-oriented answer is that the OS creates a process space (including code loading, heap and stack creation, etc.). He then puts the vector of the command line arguments at the location, and then copies the address of the argument vector to β€œargv” on the stack and the number of words to β€œargc”.

Only after performing these tasks does the OS allow the process to complete.

+3
source

Command line arguments are stored in application memory. Exactly where it differs from OS to OS, I assume that this usually happens at the bottom of the heap. The code that places it there is in the kernel source code for exec on Unix-like operating systems, but not sure where it will be on Windows (but you cannot see the source anyway). The C execution code (where "crt" comes from) takes argv and argc from the stack, and then calls main. If you're interested in learning more about running the executable on Linux, this article by Ulrich Drapper (the keeper of glibc) may make a difference: http://people.redhat.com/drepper/dsohowto.pdf

0
source

on Linux: command line arguments will be stored on the stack. do not confuse the environment variable with command line arguments, the process address space has a separate memory area for environment variables

0
source

Source: https://habr.com/ru/post/1299076/


All Articles