Linux Basics/Package management, process management
Package management Edit
Function: Installing applications and its components.
There are two base formats:
- RPM-based systems (RedHat, CentOS, Fedora, openSUSE) have rpm command for package management. One of its wrapper program is dnf. In openSUSE zypper is used for installation.
- One of Debian GNU/Linux's wrapper program is in apt package. In the beginning apt-get was used, but since then an apt command appeared, which is the improved version of apt-get.
- apt stands for Advanced Packaging Tool.
- Package management was hard a lot because of the dependencies, so it had to be simplified.
- There are console and graphical frontends for package management.
Process management Edit
- The process is an existing copy of the started program.
- The most important task of operating systems are the process management.
- PID 0 is reserved, PID 1 is for the init. (Process IDentifier)
- In a system there must not be two identical PIDs simultaneously.
- Every process is created by an existing process except the first (init) process. We're gonna call the first process in the following as parent process (its identifier is usually called as PPID), and the freshly created one is called child process.
- Of course the rules of the real life are also valid here, one process can be another process' child for the time, but it can be a parent process hence it can have many child processes.
- Those processes which show 2 as PPID (this would be weird for other UNIX and UNIX-like system users because in other systems the system process's property is PPID=0), are parts of the kernel (and can't be found binary with this filename) and they can be only seen as a process for administration, scheduling reasons. Their name are kernel-level, kernel- or just system processes. For the system processes no permission managements are valid.
- Processes in their lifetime use some CPU resources and memory and load the computer's I/O subsystem. The termination of a process has a phase when the process exists as "zombie" in the system..
- We can get information about process directly via /proc filesystem or we can get it by ps command.
- R: running
- S: interruptable sleep → The process waits for an event or resource and it can be interrupted by a signal. For example it waits for a counter (sleep) or any I/O operation.
- D: uninterruptable sleep → The process waits for an event or resource and it cannot be interrupted by a signal. Usually this state is for waiting for some I/O device.
- T: Stopped / Traced: Here goes a process if we press CTRL+Z from terminal when it's running and we drop it into the background
- X: dead: this state can't be seen
- Z: zombie process: terminated, it stayed in memory
- see „man ps”
- The first real process is init, and in the new systems systemd, which has an identifier of 1. The following started processes originate from that process, so the processes in relation create a tree-like structure → pstree
- The „job” term: We can execute in the terminal with a command multiple operations / processes for e.g.:
$ cat something.txt | grep apple
- Here the terminal starts 2 processes and between them it a pipeline, hence creating a need for a new term, which explains the started processes.
- Command for following processes:
- Processes can run in foreground and in background: FG, BG
- We can terminate processes running in foreground by pressing CTRL+C in the terminal
- We can terminate processes running in foreground by pressing CTRL+Z in the terminal
- Processes we want to run in background is with & character, e.g.:
sudo apt update &
- Running multiple command one after another automatically: with && characters, e.g.:
sudo apt update && sudo apt upgrade
Process management commands Edit
ps: list and status of processes
pstree: process structure list
wait: [n] → it waits for an arbitrary number of jobs/processes and it will give the exit code of them
atop: it lists the processes dynamically (like Task Manager in Windows)
nice: increasing or decreasing priority of a process, the lower number indicate higher priority, e.g.:
nice -n 3 program-name
We can modify the program's priority while it's running, by using renice:
renice -n 3 -p PID
Signals, terminating process Edit
- A process can be suspended "from outside" via sending a signal. We can list all the signals by entering kill -l
- For termination we need the PID, and the permission for the process from the user. Of course, we can terminate other's processes with superuser privilege.
- Killall command kills every process which is associated with the main process, for example, killall conky will kill every process that is associated with conky.
List of signals Edit
|SIGINT||2||Instant halt, CTRL+C, but the program can ignore it|
|SIGQUIT||3||The process stops and clears its files|
|SIGKILL||9||Instant halt and the program cannot ignore the kill command|
|SIGABRT||6||Abort, the program initiates it|
|SIGHUP||1||Hang up and restart (most daemons reload their configs)|
|SIGTERM||15||Stops and frees up resources|
- it uses one program's output as an input for other program
- For example:
ifconfig | grep eth0