Fundamentals_ Linux Processes Execution
Fundamentals_ Linux Processes Execution
Now what?
cat /flag
1. A process is created.
2. Cat is loaded.
3. Cat is initialized.
4. Cat is launched.
5. Cat reads its arguments and environment.
6. Cat does its thing.
7. Cat terminates.
Cat reads its arguments and
environment.
int main(int argc, void **argv, void **envp);
In the past, this was an on-demand process and carried great peril.
In modern times, this is all done when the binary is loaded, and is
much safer.
This is primarily done via system calls (man syscalls). Each system
call is well-documented in section 2 of the man pages (i.e., man 2
open).
There are over 300 system calls in Linux. Here are some examples:
int open(const char *pathname, int flags) - returns a file new file descriptor of the open file (also
shows up in /proc/self/fd!)
ssize_t read(int fd, void *buf, size_t count) - reads data from the file descriptor
ssize_t write(int fd, void *buf, size_t count) - writes data to the file descriptor
pid_t fork() - forks off an identical child process. Returns 0 if you're the child and the PID of the child if
you're the parent.
int execve(const char *filename, char **argv, char **envp) - replaces your process.
pid_t wait(int *wstatus) - wait child termination, return its PID, write its status into *wstatus.
long syscall(long syscall, ...) - invoke specified syscall.