OS Concepts
Every Process has an address space (core image) (a list of memory locations which the process can read and write) -> contains the executable program, data, and its stack. (stack pointer and program counter too).
When the program is suspended, all the information regarding the program is stored in process table (array of structures) for bringing it back to execution.
Signal Handling in Processes
Sometimes there is a need to convey information to a running process that is not actively looking for it
To guard against message loss, the sender can request the OS to notify it after a certain number of seconds. This allows the sender to retransmit the message.
When the specified time elapses, the OS sends an alarm signal to the process. Temporarily suspends its current task, and saves its state and execute the signal handling procedure.
User Identification
UID - assigned by admin for each user. Every process started by a user inherits it. Child process have the same UID as parent.
GID - for permissions
Superuser - Godfather.
Addresses
Each process is allocated a set of addresses it can use. Modern Computers often have 32 or 64 bit addresses, creating an address space 2^32 or 2^64 bytes.
Files
Everything is treated as a file We must mount an external storage device so that its file tree is attached to the root file system
- Block Special File - Model devices with blocks (SSD, Hard Disk) - so we can access in any block
- Character Specials File - Model devices that accepts or output a character stream, they are in /dev directory. /dev/lp might be the printer. A pipe is a sort of pseudofile that can be used to connect to two processes.
Protection
Files in UNIX are protected by assigning each one a 9 bit binary protection code.
Making a System Call
Making a system call involves entering the kernel.
The process typically involves storing parameters in registers, call a procedure, and using a trap instruction to switch to kernel mode.
Kernel examines the system call number and dispatches the request and executes it
in POSIX - mapping is not one to on , some procedures may be handled in user space for performance reasons.
(RDI, RSI, RDX, RCX), if there are more than six arguments, pushed to stack. (RAX contains the system call code an then taps to kernal mode for execution)

Forking a process to create a child process shares everything including the memory location, registers and such. Then we have to change the core image of the child process.
pid = waitpid(pid, &status, environp);
s = execve(name, argv, environp);
n = read(fd, buffer, nbytes);
n = write(fd, buffer, nbytes);
position = lseek(fd, offset, whence);
s = stat(name, &status);
Process in UNIX have three segments - text segment, data segment and stack segment.
There is a gap of unused address space between the data segment and the stack segment. Stack can automatically grow into this gap as needed.
brk system call is used to specify the new address where the data segment should be.
mmap system call creates a new virtual memory areas.
when opening file, code is also required - O_RDONLY, O_WRONLY, O_RDWR. To create a new file - O_CREAT.
lseek - three parametes, the file descriptor, offset and relative to beginning of the file or end of the file.