operating system

structure
files are stored in a hierarchical filesystem
root or simply "/" = top node of the system
whenever possible, Linux makes its components available via files or objects that look like files
processes, devices, and network sockets are all represented by file-like objects,
and can often be worked with using the same utilities used for regular files
Linux is a fully multitasking multi user operating system,
with built-in networking and service processes known as daemons in the UNIX world
kernel = core of OS
image.png
partition
physically contiguous section of a disk, or what appears to be so in some advanced setups.
image.png
image.png
partition table
partição
mount / type
size
location
1
OS = root
primary
12 - 20 GB
beginning
2
RAM
swap
1.5-2 * RAM
end
3
docs etc.
/home
There are no rows in this table
image.png
drives and/or partitions are mounted as directories in the single filesystem
removable media such as USB drives will show up as mounted at run/media/username/disklabel
filesystem names are case-sensitive,
/boot, /Boot, and /BOOT represent three different directories (or folders)
every user has a home directory such as /home/username
mount points
a mount point is simply a directory, usually empty
filesystem table → /etc/fstab
image.png
Search
command
what it does
INPUT
1
sudo mount device_node mount_point
attach a filesystem somewhere within the filesystem tree
sudo mount /dev/sda5 /home
2
mount
display all presently mounted filesystems
3
sudo umount mount_point
unmount partition
sudo umount /home
4
df -Th
disk-free
display information about mounted filesystems
There are no rows in this table
boot process
secure boot pass = silver7471
image.png
Basic Input/Output System (BIOS)
initializes the HW, including screen and keyboard, and tests the main memory
this process is also called POST (Power On Self Test)
BIOS SW is stored on a ROM chip on the motherboard
remainder of boot process is controlled by OS
boot loader
responsible for loading the kernel image and the initial RAM disk or filesystem
(which contains some critical files and device drivers needed to start the system) into memory
image.png
usually stored on one of the hard disks in the system
for traditional BIOS/MBR systems: in the boot sector
image.png
image.png
for more recent (Unified) Extensible Firmware Interface or EFI/UEFI systems: in the EFI partition
ST stage: boot loader examines the partition table and finds a bootable partition
ND stage: resides under /boot
splash screen is displayed, allowing to choose which OS to boot.
boot loader loads the kernel into RAM and passes control to it.
kernels are almost always compressed, so its first job is to uncompress itself.
after this, it will check and analyze the system HW and initialize any HW device drivers.
udev (user device) is responsible for figuring out which devices are present, locating the device drivers and loading them.
examples
GRUB (for GRand Unified Boot loader)
ISOLINUX (for booting from removable media)
DAS U-Boot (for booting on embedded devices/appliances)
boot loader passwords
you can secure the boot process with a secure password to prevent someone from bypassing the user authentication step.
this can work in conjunction with password protection for the BIOS.
using a bootloader password alone will stop a user from editing the bootloader configuration during the boot process,
but it will not prevent a user from booting from an alternative boot media such as optical disks or pen drives.
this is done using a BIOS password for full protection.
to set a password for grub, never edit grub.cfg directly;
instead, modify configuration files in /etc/grub.d and /etc/defaults/grub,
and then run update-grub, or grub2-mkconfig and save the new configuration file.
to learn more, read: .
initial RAM disk
initramfs filesystem image contains programs and binary files
that perform all actions needed to mount the proper root filesystem
the mount program instructs the operating system that a filesystem is ready for use,
and associates it with a particular point in the overall hierarchy of the filesystem (the mount point)
/sbin/init
handles the mounting and pivoting over to the final real root filesystem
init starts a number of text-mode login prompts
besides starting the system,
init is responsible for keeping the system running and for shutting it down cleanly.
one of its responsibilities is to act when necessary as a manager for all non-kernel processes;
it cleans up after them upon completion, and restarts user login services as needed
when users log in and out, and does the same for other background system services.
service = program that runs as background process
examples: httpd, nfsd, ntpd, ftpd, named
image.png
systemmd
systems with systemd start up faster than those with earlier init methods
it replaces a serialized set of steps with aggressive parallelization techniques,
which permits multiple services to be initiated simultaneously
configuration files enumerate what has to be done before a service is started
/sbin/init just points to /lib/systemd/systemd; i.e. systemd takes over the init process
login
available text terminal will prompt for a username (with the string login:) and password
you can also connect and log into remote systems by using Secure SHell (SSH)
virtual terminals
console sessions that use the entire display and keyboard outside of a graphical environment
although there can be multiple active terminals, only one terminal remains visible at a time
Search
command
what it does
1
sudo systemctl start | stop | restart some_service
start, stop, restart service on a currently running system
2
sudo systemctl enable | disable some_service
enable or disable system service from starting up at system boot
3
ssh student@remote-server.com
SSH connects securely to remote machine (remote-server.com)
and give student a command line terminal window,
using either a password (as with regular logins)
or cryptographic key to sign in to verify the identity
4
bash
start new shell
5
shutdown
preferred method to shut down the system.
it is important to always shut down properly.
failure to do so can result in damage to the system and/or loss of data.
6
halt
stop all CPU functions
7
poweroff
shutdown -h
8
reboot
shutdown -r
There are no rows in this table
processes
a process is simply an instance of one or more related tasks (threads) executing on your computer
it is not the same as a program or a command
a single command may start several processes simultaneously
some processes are independent of each other and others are related
a terminal window is a process that allows users to execute programs and access resources in an interactive environment
image.png
process types
image.png

priorities
image.png
the PID (unique process ID#) is used to track state, CPU usage, memory use, where resources are located in memory, etc.
init process → PID = 1
image.png
at any given time, many processes are running (i.e. in the run queue) on the system
however, a CPU can actually accommodate only one task at a time (!!!)
Linux allows you to set and manipulate process priority
priority for a process can be set by specifying a nice value, or niceness, for the process.
the lower the nice value, the higher the priority
a process with a high nice value simply allows other processes to be executed first
highest priority → nice = -20
lowest priority → nice = +19
a neutral niceness of zero means the default priority of 80, which is what all normal processes start out with in linux
you can also assign a so-called real-time priority to time-sensitive tasks
image.png
load average = average of load number for given period of time
it takes into account processes
actively running on a CPU.
waiting for CPU to become available.
sleeping: waiting for some kind of resource (typically, I/O)
displayed using three numbers
0,78 = for the last minute system has been 78% utilized on average
0,83 = for the last 5 minutes utilization has been 83%
0,95 = for the last 15 minutes utilization has been 95%
for a single-CPU system
a value of 1.00 is good if we want to fully use a system
a value over 1.00 implies that system was over-utilized: there were more processes needing CPU than CPU was available
for a system with more than 1 CPU (quad-CPU system), divide load average numbers by the number of CPUs (divide by 4)
short-term increases are usually not a problem
if a high peak is seen in the 5 and 15 minute load averages, it may be cause for concern
Search
command
what it does
INPUT
OUTPUT
1
ps
list of processes launched underneath terminal window
2
ps -f
list of processes with IDs
3
ps -l
list of processes with priority and niceness
4
ps lf
list of processes with more details
5
renice some_value process_ID
change niceness of process in value amount
renice +5 82543
sudo renice -5 82543
adds 5 to nice value
subtracts 5 of nice value
6
w
top
top | head
uptime
display load average
7
jobs
display all jobs running in background
8
jobs -l
display all jobs in background with PID
9
some_command &
run command in background
10
bg
put most recent job in background
11
fg
put most recent job in foreground
12
CTRL+Z
suspend foreground job
13
kill -SIGKILL process_ID
kill -9 process_ID
terminate process or kill application
14
ps -ef
list of all processes running in the system
system V style
15
ps -eLf
one line of information for every thread
system V style
16
top
utility to interactively monitor what processes and tasks are doing on your system.
constant real-time updates (every two seconds by default)
17
q.top
exit top
18
ps -eLf | less
to display info slower
19
ps aux
all processes of all users
ps aux | head -10
BSD style
20
ps axo
allows to specify attributes to display
ps axo stat,priority,pid,pcpu,comm | head -10
BSD style
21
pstree
process tree
22
vmstat
estatísticas sobre a memória virtual
vmstat -a 2 1000
run every 2 seconds a 1,000 times
There are no rows in this table
foreground x background job processing
a job in this context is a command launched from a terminal window
when 1 foreground job is running, other jobs need to wait for shell access (at least in that terminal window if using the GUI)
if the current job is going to take a long time to complete, it can run in the background and free the shell for other tasks
the background job will be executed at lower priority, allowing smooth execution of interactive tasks
by default, all jobs are executed in the foreground
process tree
processes running on the system in the form of a tree diagram
showing the relationship between a process and its parent process and any other processes that it created.
image.png
top
the 1st line displays a quick summary of what is happening in the system, including:
how long the system has been up
how many users are logged on
the load average
the 2nd line displays the total number of processes, the number of running, sleeping, stopped, and zombie processes.
comparing the number of running processes with the load average helps determine if the system has reached its capacity
the 3rd line indicates
how the CPU time is being divided between the users (us) and the kernel (sy)
by displaying the % of CPU time used for each.
the % of user jobs running at a lower priority (niceness - ni)
idle mode (id) should be low if the load average is high, and vice versa
the % of jobs waiting (wa) for I/O
the % of hardware (hi) vs. software interrupts (si)
steal time (st) is generally used with virtual machines, which has some of its idle CPU time taken for other uses.
the 4th and 5th lines of the top output indicate memory usage → total memory, used memory and free space
line 4 → Physical memory (RAM)
lina 5 → Swap space
once the physical memory is exhausted,
the system starts using swap space (temporary storage space on the HD) as an extended memory pool.
since accessing disk is much slower than accessing memory, this will negatively affect system performance.
top of the table
by default, processes are ordered by highest CPU usage.
the following information about each process is displayed:
Process Identification Number (PID)
Process owner (USER)
Priority (PR) and nice values (NI)
Virtual (VIRT), physical (RES), and shared memory (SHR)
Status (S)
Percentage of CPU (%CPU) and memory (%MEM) used
Execution time (TIME+)
Command (COMMAND)
image.png
interactive keys with top
top can be utilized interactively for monitoring and controlling processes
you can enter single-letter commands to change its behavior
image.png
Search
command
output
1
1
statistics for each CPU instead of just the amount that made the total
2
H
a listing of what the possible keys I can hit are and what they do.
There are no rows in this table
scheduling jobs in the future
Search
command
what it does
INPUT
OUTPUT
1
at
starts execution of non-interactive task at a specific time
at now + 2 days
2
atq
display queue of jobs scheduled with at
1 Thu Feb 10 17:45:00 2022 a thais
3
crontab
time-based scheduling utility program, for periodic tasks.
driven by a configuration file called /etc/crontab (cron table)
if the machine is not up at the time the job is scheduled, anacron will run the job at a suitable time.
4
crontab file_name
file with job to run periodically
5
crontab -e
open crontab editor to edit existing jobs or create new jobs
6
crontab -l
list jobs scheduled with cron
7
crontab -r
remove job scheduled with cron
8
sleep some_number[suffix]
delays execution of command for a specific period
suffix may be s for seconds (default), m for minutes, h for hours, d for days.
There are no rows in this table
each line of the crontab file will contain 6 fields
entry * * * * * /usr/local/bin/execute/this/script.sh will schedule a job to execute script.sh
every minute of every hour of every day of the month, and every month and every day in the week.
entry 30 08 10 06 * /home/sysadmin/full-backup will schedule a full-backup
at 8.30 a.m., 10-June, irrespective of the day of the week.
image.png
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.