A C program starts execution with a function called main( ). The prototype for the main function is
int main(int argc , char **argv)
where argc is the number of command line arguments and argv is an array of pointers to the arguments.
When a C program is executed by the kernel - by one of the exec functions, a special start up routine is called before the main function is called. The executable program file specifies this routine as the starting address of the program; this is set up the link editor when it is invoked by C compiler. This start up routine takes values from the kernel - the command line arguments and the environment and sets this up so that main function is called.
A note about exec function:
When a process calls the exec functions, that process is completely replaced by a new program and the new program starts executing at its main function. The process ID doesn't change across exec because a new process is not created; exec mere replaces the current process - its text, data, heap and stack segments with a brand new program from disk.





0 comments