[OT] Re: [Vm-dev] argCnt, argVec, engVec alternatives

David T. Lewis lewis at mail.msen.com
Thu Jan 6 13:20:40 UTC 2011


On Wed, Jan 05, 2011 at 08:18:15PM +0100, Igor Stasenko wrote:
> 
> i can't believe that there is no way to get a command line other than
> from main() function in unix.
> utils, like 'ps ax' indicating that its possible :)
> 
> At least in windows , there is a GetCommandLine() for that.
> 

<OT>
I hope I'm not being insulting, but I'm assuming you meant this
as a serious comment, so for background just in case this is not
generally known:

The basic model for process creation in Unix systems is the idea
of a fork() followed by an exec() call. The running system starts
with a single proto-process called "init", and every other running
process on the system is a descendent of that process, with each
child process created by its parent using fork() and exec()
system calls.

The fork() call creates a clone of the running process, and exec()
loads and runs a new program in that newly created process. The
exec() call sets up the argument list and environment for the new
program, and the remainder of the process is simply inherited from
the parent process that created it. The C programmer sees this as
the entry point to a program as a function called main() with
arguments supplied by the exec system call:

  int main(int argc, char *argv[], char *envp[])

Every Unix program written for the last 30 years works like this,
so no additional system services are required for a program to
access the argument list and environment for its process. The

On Windows, the conventions for program entry points (WinMain)
are different, but there are win32 calls available to provide
functions equivalent to the Unix conventions. GetCommandLine()
is an example of this.

On a Linux system, the exec() call is implemented as execve(),
so the manual page is "man 2 execve" for the modern equivalent
of exec().
</OT>

Dave



More information about the Vm-dev mailing list