What operations are performed by the kernel when handling the `execve()` system call? Include details about permission checks, loading the executable, and setting up the new process image.
The kernel has a table of system call handlers, known as the system call table. Each entry in this table is called a system call number. For execve, the kernel looks up the system call number in this table and dispatches the call to the appropriate handler function.
Permission checks:
The execve handler checks if the file path exists.
It checks if the current process has execute permissions.
It checks if the file is a valid executable format(ELF).
Loading the New Executable:
The kernel reads the ELF file from disk into memory.
It parses the ELF file headers to determine how to set up the new process image.
Setting up the new process image:
The kernel frees up the process context of the current process and creates new one for the new process.