SYS_EXIT
Terminate the calling process with an exit code. Syscall Number: 0Parameters
Exit status code to return to parent process via waitpid
Returns
This syscall does not return. The process transitions to ZOMBIE state and the scheduler runs.Behavior
When a process exits:- The process state changes to
PROC_ZOMBIE - The exit code is stored in
procs[pid].exit_code - SIGCHLD is sent to the parent process
- If the parent is blocked in
waitpid, it is awakened - All children are reparented to PID 0
- The scheduler is invoked to run another process
Example
SYS_FORK
Create a child process by duplicating the calling process. Syscall Number: 3Parameters
NoneReturns
- In parent process: child PID (positive integer)
- In child process: 0
- On error: -1
Behavior
Creates a new process that is an exact copy of the calling process:- Address space is duplicated via copy-on-write page tables
- File descriptor table is copied
- Signal handlers are inherited
vruntime, priority, and timeslice are copied- Child starts with empty pending signals
- Child’s parent PID is set to the caller’s PID
- Child’s state is set to
PROC_READY
Implementation
Example
SYS_EXECVE
Replace the current process image with a new program loaded from an ELF binary. Syscall Number: 4Parameters
Path to the ELF executable file
Argument vector (currently unused)
Environment variables (currently unused)
Returns
- On success: does not return (execution starts at ELF entry point)
- On error: -1
Behavior
- Resolves the file path using VFS
- Reads the entire ELF file into kernel memory
- Parses and loads ELF segments into the current process’s address space
- Allocates a new user stack (4 pages at
0x7FFFFF000) - Updates process context (RIP, RSP, RBP) to start at ELF entry point
- Returns to user mode at the new entry point
The current implementation is marked as “Stub” in the API reference but is fully functional. File descriptors and signal handlers are preserved across execve.
Example
SYS_WAITPID
Wait for a child process to change state (exit or be killed). Syscall Number: 5Parameters
> 0: Wait for specific child with this PID-1: Wait for any child process
Pointer to store child’s exit code (can be NULL)
Returns
- On success: PID of the child that exited
- On error or no children: -1
Behavior
This is a blocking syscall. If no matching zombie child exists, the caller is blocked (state set to
PROC_BLOCKED) until a child exits.- First scan: Check for already-zombie children
- If none found: Block the process and reschedule
- After wakeup: Scan again for zombie children
- On match: Reap the zombie (set state to
PROC_UNUSED) and return its PID
Example
SYS_YIELD
Voluntarily yield the CPU to the scheduler. Syscall Number: 2Parameters
NoneReturns
Always returns 0
Behavior
Callsschedule() to invoke the scheduler. The current process remains in PROC_RUNNING state but is moved to the back of its priority queue, allowing other processes to run.
Example
SYS_GETPID
Get the process ID of the calling process. Syscall Number: 30Parameters
NoneReturns
Current process ID (0 to PROC_MAX-1)
Example
SYS_KILL
Send a signal to a process. Syscall Number: 29Parameters
Target process ID
Signal number (9 = SIGKILL, 11 = SIGSEGV, 13 = SIGPIPE, 17 = SIGCHLD)
Returns
- On success: 0
- On error (invalid PID or unused process): -1
Behavior
For other signals:- The signal bit is set in
procs[target].pending_signals - If the process has registered a handler via
SYS_SIGACTION, it will be invoked - Signals are delivered on return to user mode
Example
SYS_SIGACTION
Register or query a signal handler. Syscall Number: 32Parameters
Signal number (0-31)
Function pointer to signal handler, or
SIG_DFL (0) or SIG_IGN (1)If non-NULL, receives the previous handler
Returns
- On success: 0
- On error (invalid signal or attempt to catch SIGKILL): -1
Example
SYS_CLOCK
Get a timestamp from the Time Stamp Counter (TSC). Syscall Number: 18Parameters
Clock identifier (currently ignored)
Pointer to timespec structure (currently ignored)
Returns
Current TSC value (CPU cycle counter)
Implementation
SYS_NANOSLEEP
Sleep for a specified duration. Syscall Number: 35Parameters
Duration to sleep in nanoseconds
Returns
Always returns 0 after waking
Behavior
Converts nanoseconds to system timer ticks (1 kHz PIT), setswake_tick, and blocks the process until the timer interrupt handler wakes it.