Skip to content

Instantly share code, notes, and snippets.

@okram999
Last active February 8, 2019 21:05
Show Gist options
  • Save okram999/decf22044845b13ea5638cdd7d01050c to your computer and use it in GitHub Desktop.
Save okram999/decf22044845b13ea5638cdd7d01050c to your computer and use it in GitHub Desktop.
Linux Core
Process:
- instance of a computer prg in execution
- while running a code, the code is loaded from disk to memory
Threads:
- A process can run the program parrallely executing various instructions parallely
- Each thread have their own stacks
- But shares - Text, heap, etc
A process in memory is divided as :
1. Text --> code is stored
2. Global Variables --> Global Variables in the code
3. stack --> local variables and functions created at the compile time
4. Heap --> DYNAMICALLY ALLOCATED MEMORY USING , 'malloc()' Data structure allocated at run time stays in heap. -->
5. Shared libs -> stays between Stack and Heap
The Operating system - allocates resources to a process based on the owner of the process thus creating a security setup.
Process Stats:
1. NEW
2. READY
3. RUNNING
4. WAITING
5. TERMINATED
Process Creation in Unix:
- Created from 'init' , apple calls it 'launchd'
- Child process is creating by 'forking' (system call called fork() ) the parent process
EXEC 'ing in processes:
- Unix systems starts a new program by 'exec'ing a child process, which was forked from the parent process
## how does a process run in unix:
e.g.: when i type 'ls'
- The shell makes the system call 'fork()', and clones itself
- Then an exec is performed on the new process 'exec /bin/ls'
Process table:
-> Its a data structure maintained by the OS in the RAM.
-> This store PID, PROCESS NAME, PRIORITY etc
Zombie Process:
-> Processes that have completed the execution but are not yet removed from the process tables.
-> This can be a child processes in "TERMINATED" state, required by the parent process to read the exit status. Before its "REAPED"
-> Zombie processes are created when the parent does not reap the child. This can happen due to parent not executing the wait()
system call after forking.
Orphaned process:
-> an orphan process is a process that is still executing, but whose parent has died.
-> These do not remain as zombie processes; instead, (like all orphaned processes) they are adopted by init (process ID 1), which wait s on its children.
Unix Command to check process:
-> ps -A
-> ps -aux
INTERPROCESS COMMUNICATIONS (IPC):
- Signals (not usually used to transfer data but instead used to remotely command the partnered process.)
- Pipes (Annonymous)
- Named Pipes (FIFO)
- Shared Memory (SysV Shared Memory & POSIX Shared Memory)
- Unix Sockets
- Msg Queue: A data stream similar to a socket, but which usually preserves message boundaries.
Typically implemented by the operating system, they allow multiple processes to read and write
to the message queue without being directly connected to each other.
Unix Sockets:
-> IP_ADDRESS, PORT & PROTOCOL makes up a socket. And it is the endpoint to reach to an application to
-> Communication Type: SOCK_STREAM/SOCK_DATAGRAM for TCP or UDP
PORT:
-> In computer networking, and more definitely in software terms, a port is a logical entity which acts as a endpoint of
communication to identify a given application or process on an Linux operating system.
-> It is a 16-bit number (0 to 65535) which differentiates one application from another on end systems.
## Daemonize a Process:
## UMASK (default: 002) /etc/bashrc
By default:
dir --> 775
file --> 664
# stdin,stdout 1> and stderr 2> (Three streams)
- &> both streams std out and std. err
- /dev/null - a device where everything is discarded
## Signal was not recieved:
During critical section execution, some processes can setup signal blocking.
The system call to mask signals is ‘sigprocmask’. When the kernel raises a blocked signal, it is not delivered.
Such signals are called pending. When a pending signal is unblocked, the kernel passes it off to the process to handle.
It is possible that the process was masking SIGHUP.
## TCP slow start:
-- Tcp slow start is a congestion control algorithm that starts by increasing the TCP
congestion window each time an ACK is received, until an ACK is not received.
## DHCP
- Discover
- Offer
- Request
- Acknowledge
# Difference between TCP/UDP
Reliable/Unreliable
Ordered/Unordered
Heavyweight/Lightweight
Streaming
Header size
# Network Address Translation (NAT)
- SNAT
- DNAT
# /etc/fstab
e.g: LABEL=/ / ext4 defaults,noatime 1 1
[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass] (1 for root device,
#Soft and Hardlink
-- Shares same inode
-- Soft link is broken if source file is renamed
# Boot process with GRUB2 & systemd
1. Once the linux is powered on, BIOS POST is started to test the hardwares
2. It get the master boot record and loads to memory and passes the control
3. Grub2 have the config under /boot/grub2 will have the kernel information, and it will also load the root filesystem
in the grub cfg.
4. Kernel is self extracted and loaded and starts the systemd process (instead of init)
5. systemd is the mother of all other process.
-- first it reads the /etc/fstab and mounts all the fs
-- then it reads the configure" /etc/systemd/system/default.target to determin
state or target, into which it should boot the host.
# LVM on centos/RHEL
- create partition with type 8e
- create PV
- Create VG
- Create LV
- Create filesystem of the LV
- mount it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment