Last Sync: 2022-05-26 08:30:05

This commit is contained in:
tactonbishop 2022-05-26 08:30:05 +01:00
parent 6f90af31a6
commit d14f25c4e3
4 changed files with 74 additions and 2 deletions

View file

@ -17,7 +17,7 @@ The kernel acts as the primary mediator between the hardware (CPU, memory) and u
> A process is just another name for a running program. Process management is the starting, pausing, resuming, scheduling and terminating of processes.
On modern computers it appears that multiple processes can run simultaneously at once. This is only because the processor is so fast that we do not detect changes. In fact access to the CPU is always sequential. The sequence in which multiple programs are allowed to access the CPU is managed by the kernel.
On modern computers it appears that multiple processes can run simultaneously at once. This is only because the processor is so fast that we do not detect changes. In fact access to the CPU is always sequential. The sequence* in which multiple programs are allowed to access the CPU is managed by the kernel.
> Consider a system with a one-core CPU. Many processes may be _able_ to use the CPU, but only one process can actually use the CPU at any given time...Each process uses the CPU for a fraction of a second, then pauses, then another process uses it for a fraction of a second and so on... (_How Linux Works: Third Edition_, Brian Ward 2021)

View file

@ -4,6 +4,8 @@ tags:
- shell
---
# File permissions and executables
Every Unix file has a set of permissions that determine whether you can read, write or run (execute) the file.
## Viewing file permissions
In order to see file permissions within the terminal, use the `-l` or `-rfl` with the `ls` command. Remember this command can be applied at both the directory and single-file level. For example:
@ -17,7 +19,27 @@ drwxr-xr-x 12 thomas thomas 4096 Sep 19 17:41 thomas-bishop
drwxr-xr-x 5 thomas thomas 4096 Sep 4 19:24 ts-kata
````
## `chmod`
### What the output means
The first column of the permissions output is known as the file's *mode*. The sequence from left to right is as follows:
```
- - - - - - - - - -
type user permissions group permissions other permissions
```
<dl>
<dt>type</dt>
<dd>The file type. A dash just means an ordinary file. `d` means directory </dd>
<dt>user permissions</dt>
<dd>read, write or execute. A dash means 'nothing': the permissions for that slot in the set have not be assigned</dd>
<dt>group and other</dt>
<dd>group is obviously what anyone belonging to the current file's user group can do. Everyone else (outside of the user and the group) is covered by the other permissions, sometimes known as 'world' permissions</dd>
</dl>
## Modifying permissions: `chmod`
We use `chmod` for transferring ownership and file permissions quickly from the command-line.

View file

@ -0,0 +1,50 @@
---
tags:
- Programming_Languages
- shell
- processes
---
# Processes (`ps`)
`ps` allows us to control [user processes](../../Operating_Systems/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
```
<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`