When I try
strace ping google.com
or
strace ls
or
even strace curl <domain>
The first two systemcalls are always,
execve("/usr/bin/curl", ["curl", "google.com"], 0x7ffecf1bc378 /* 61 vars */) = 0
brk(NULL) = 0x55f553c49000
Can someone please tell me if execve will always be the first systemcall when I execute anything?
I read this manual page, https://linux.die.net/man/2/execve
But don't understand if execve
is really a system call or executable program?
Best Answer
In Linux a new process is created via
fork()
, which makes a child process which is almost identical to the parent process. To create a new process whose program is different than the program of the original process, the new child process immediately callsexecve()
, which is basically the process saying "replace my current program with this other program".brk(NULL)
is the process asking where its heap memory ends. Many programs call this as their first system call (which will show up right afterexecve()
) because they usemalloc()
right away (or a library call they make usesmalloc()
internally). If the program and its library calls don't need to callmalloc()
for a while then something besidesbrk(NULL)
will be the second system call.