Autosave: 2024-06-21 06:30:05

This commit is contained in:
thomasabishop 2024-06-21 06:30:05 +01:00
parent 070b6b2230
commit c09b829510
4 changed files with 99 additions and 78 deletions

Binary file not shown.

View file

@ -1,78 +1,21 @@
--- ---
tags: id: t70u
- shell title: Processes
- Linux tags: [operating-systems]
created: Friday, June 21, 2024
--- ---
# Processes (`ps`) # Processes
`ps` allows us to control [user processes](The_kernel.md) Programs are sequences of machine instructions stored in a file. However they do
from the shell. not work by themselves. Something needs to load the file's intructions into
memory and direct the CPU to run the program. The OS does this via processes.
The command in its most minimal application returns the following A process **is a running instance of a given program**. It can be thought of as
a container in which a program runs. This container includes:
``` - a copy of the program code loaded into memory
PID TTY TIME CMD - a memory address
2437 pts/2 00:00:01 zsh - other information about the state of the process
7112 pts/2 00:00:00 ps
```
With the `-e` modifier we can list more processes: ## Related notes
```
PID TTY TIME CMD
1 ? 00:00:05 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
5 ? 00:00:00 netns
7 ? 00:00:00 kworker/0:0H-events_highpri
9 ? 00:00:00 mm_percpu_wq
11 ? 00:00:00 rcu_tasks_kthread
12 ? 00:00:00 rcu_tasks_rude_kthread
13 ? 00:00:00 rcu_tasks_trace_kthread
14 ? 00:00:08 ksoftirqd/0
15 ? 00:03:20 rcu_preempt
16 ? 00:00:00 rcub/0
17 ? 00:00:00 migration/0
18 ? 00:00:00 idle_inject/0
20 ? 00:00:00 cpuhp/0
21 ? 00:00:00 cpuhp/1
22 ? 00:00:00 idle_inject/1
23 ? 00:00:00 migration/1
```
<dl>
<dt>pid</dt>
<dd>Process ID: every currently running process has a unique ID<dd>
<dt>tty</dt>
<dd>The terminal device where the process is running<dd>
<dt>Time</dt>
<dd>The amount of CPU time in minutes and seconds that the process has used so far. The total amount of time that the process has spent running instructions on the processor.<dd>
<dt>cmd</dt>
<dd>The command used to run the program. Note this can change during the running of the program.<dd>
</dl>
## Modifiers
<dl>
<dt><code>ps x</code></dt>
<dd>Show all running processes<dd>
<dt><code>ps ax</code></dt>
<dd>Show all processes not just the ones you, the current user, own<dd>
<dt><code>ps u</code></dt>
<dd>Show detailed info on processes<dd>
<dt><code>ps w</code></dt>
<dd>Show full command names<dd>
</dl>
## Process termination
The general schema is: `kill [pid]`. This allows for process clean-up. If this
doesn't succeed you can force with `KILL [pid]` which will terminate the process
immediately but is obviously more risky.
We can also start/stop processes with modifiers on `kill`:
- `kill -STOP pid`
- `kill -CONT pid`

78
zk/ps.md Normal file
View file

@ -0,0 +1,78 @@
---
tags:
- shell
- Linux
---
# Processes (`ps`)
`ps` allows us to control [user processes](The_kernel.md)
from the shell.
The command in its most minimal application returns the following
```
PID TTY TIME CMD
2437 pts/2 00:00:01 zsh
7112 pts/2 00:00:00 ps
```
With the `-e` modifier we can list more processes:
```
PID TTY TIME CMD
1 ? 00:00:05 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
5 ? 00:00:00 netns
7 ? 00:00:00 kworker/0:0H-events_highpri
9 ? 00:00:00 mm_percpu_wq
11 ? 00:00:00 rcu_tasks_kthread
12 ? 00:00:00 rcu_tasks_rude_kthread
13 ? 00:00:00 rcu_tasks_trace_kthread
14 ? 00:00:08 ksoftirqd/0
15 ? 00:03:20 rcu_preempt
16 ? 00:00:00 rcub/0
17 ? 00:00:00 migration/0
18 ? 00:00:00 idle_inject/0
20 ? 00:00:00 cpuhp/0
21 ? 00:00:00 cpuhp/1
22 ? 00:00:00 idle_inject/1
23 ? 00:00:00 migration/1
```
<dl>
<dt>pid</dt>
<dd>Process ID: every currently running process has a unique ID<dd>
<dt>tty</dt>
<dd>The terminal device where the process is running<dd>
<dt>Time</dt>
<dd>The amount of CPU time in minutes and seconds that the process has used so far. The total amount of time that the process has spent running instructions on the processor.<dd>
<dt>cmd</dt>
<dd>The command used to run the program. Note this can change during the running of the program.<dd>
</dl>
## Modifiers
<dl>
<dt><code>ps x</code></dt>
<dd>Show all running processes<dd>
<dt><code>ps ax</code></dt>
<dd>Show all processes not just the ones you, the current user, own<dd>
<dt><code>ps u</code></dt>
<dd>Show detailed info on processes<dd>
<dt><code>ps w</code></dt>
<dd>Show full command names<dd>
</dl>
## Process termination
The general schema is: `kill [pid]`. This allows for process clean-up. If this
doesn't succeed you can force with `KILL [pid]` which will terminate the process
immediately but is obviously more risky.
We can also start/stop processes with modifiers on `kill`:
- `kill -STOP pid`
- `kill -CONT pid`

View file

@ -10,13 +10,13 @@ tags:
Once the [boot process](Boot_process.md) has completed and the bootloader has Once the [boot process](Boot_process.md) has completed and the bootloader has
located the kernel and injected it into memory the first user space program located the kernel and injected it into memory the first user space program
runs: `init` (for _initialisation_). `init` is a [daemon](Daemons.md) process runs: `init` (for _initialisation_). `init` is a [daemon](Daemons.md)
that continues running until shutdown and is responsible for starting all the [process](./Processes.md) that continues running until shutdown and is
processes that are prerequisites for user space. For example: network responsible for starting all the processes that are prerequisites for user
connections, disk access, user logins etc. `init` is the parent of all space. For example: network connections, disk access, user logins etc. `init` is
processes: PID1. Whilst it does a lot of its work in quick succession at boot the parent of all processes: PID1. Whilst it does a lot of its work in quick
time it is not limited to the this stage of the lifescycle but runs continuously succession at boot time it is not limited to the this stage of the lifescycle
in reponse to new user events. but runs continuously in reponse to new user events.
On Linux systems `systemd` is used to implement `init`. On Linux systems `systemd` is used to implement `init`.