c - Working of exec family functions -


i studying exec family of functions.its man page says,it replaces current process image new process image. if replaces binary,then after returning back,how previous parameters of process called exec?as replacing process image means replacing memory sections.please correct me if wrong or having less knowledge.

the real job done execve(2) system call. other functions (like execvp ...) calling execve.

the execve quite complex system call. when successful not return. process state (including address space) has been rewritten [almost] entirely.

so basically, address space becoming fresh. contains segments binary executable.

the program arguments, environment, etc... have been copied (at bottom of stack segment) new address space. hence limited (by arg_max, typically 128kbytes -but raise recompiling kernel).

the address space change done lazily (using copy on write); in reality paging invalidated, , subsequent accesses pages fault, kernel serves providing new page, etc etc...

on linux, suggest looking /proc/ (see proc(5) more). in particular, try cat /proc/self/maps show address space map of process running cat.

of course execve used after fork(2), , dup2(2) and/or pipe(2), , waiting syscall waitpid(2) or wait4(2), perhaps handling sigchld signal -see signal(7) & sigaction(2). please read e.g. advanced linux programming (which can read online).

you consider using popen(3) or system(3) (they calling pipe popen, fork & execve of /bin/sh -c ....).


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -