Browse Source

Linux-process-management

master
zeus 4 years ago
parent
commit
a0bc6e5da3
  1. 228
      Linux-process-management/basics.adoc

228
Linux-process-management/basics.adoc

@ -1,8 +1,8 @@
= Linux process management ! = An Introduction to Linux !
Apostolos rootApostolos@swarmlab.io Apostolos rootApostolos@swarmlab.io
// Metadata: // Metadata:
:description: Linux process management :description: Intro and Install
:keywords: ps aux :keywords: Linux, apt
:data-uri: :data-uri:
:toc: right :toc: right
:toc-title: Table of contents :toc-title: Table of contents
@ -15,98 +15,130 @@ Apostolos rootApostolos@swarmlab.io
:sectnums: :sectnums:
== Absolute basics
== process
.Absolute basics
An instance of a running program is called a process. [options="header,footer"]
Every time you run a shell command, a program is run and a process is created for it. |=======================
|Command| Meaning
|ls| Displays a list of files in the current working directory.
In any modern operating system there can be more than one instance of a program loaded in memory at the same time. |cd directory| change directories
|passwd |change the password for the current user
== Linux process management |file filename| display file type of file with name filename
|cat textfile| throws content of textfile on the screen
Operating systems need some ways to create processes. |pwd| display present working directory
|exit or logout| leave this session
* In a very simple system designed for running only a single application (e.g., the controller in a microwave oven), it may be possible to have all the processes that will ever be needed be present when the system comes up. |man command| read man pages on command
* In general-purpose systems, however, some way is needed to create and terminate processes as needed during operation. |=======================
[NOTE] === Key combinations
==== .Key combinations
[options="header,footer"]
*There are four principal events that cause a process to be created:* |=======================
|Key or key combination| Function
* System initialization. |Ctrl+C| End a running program and return the prompt
* Execution of process creation system call by a running process. |Ctrl+Z| Suspend a program
* A user request to create a new process. |ArrowUp and ArrowDown| Browse history. Go to the line that you want to repeat, edit details if necessary, and press Enter to save time.
* Initiation of a batch job. |Tab| Command or filename completion; when multiple choices are possible, the system will either signal with an audio or visual bell, or, if too many choices are possible, ask you if you want to see them all.
==== |Tab Tab| Shows file or command completion possibilities.
|Shift+PageUp and Shift+PageDown| Browse terminal buffer (to see text that has "scrolled off" the screen).
Process creation in UNIX and Linux are done through *fork()* or *clone()* system calls. |=======================
There are several steps involved in process creation. === ls -l
* process scheduling, [source,bash]
* interrupt handling, ----
* signaling, # ls -al
* process prioritization, drwxrwxr-x 4 zeus zeus 4096 Οκτ 23 21:55 .
* process switching, drwxrwxr-x 9 zeus zeus 4096 Οκτ 15 14:28 ..
* process state, drwxrwxr-x 8 zeus zeus 4096 Οκτ 23 21:55 .git
* process memory drwxrwxr-x 4 zeus zeus 4096 Οκτ 14 20:24 install
crw------- 1 root root 5, 1 Οκτ 23 21:22 console
=== Life cycle of a process lrwxrwxrwx 1 root root 11 Οκτ 23 21:21 core -> /proc/kcore
drwxr-xr-x 4 root root 100 Οκτ 23 21:22 cpu
NOTE: *1->* creation *2->* execution *3->* termination *4->* removal crw------- 1 root root 10, 59 Οκτ 23 21:21 cpu_dma_latency
crw------- 1 root root 10, 203 Οκτ 23 21:21 cuse
=== process state -rw-rw-r-- 1 zeus zeus 1517 Οκτ 23 21:55 INSTALL.md
-rw-rw-r-- 1 zeus zeus 33883 Οκτ 15 14:28 LICENSE
An operating system kernel that allows multitasking needs processes to have certain states. Names for these states are not standardised, but they have similar functionality. -rw-rw-r-- 1 zeus zeus 691 Οκτ 17 11:13 README.md
----
[.float-group] ==== File types
--
[.right] This table gives an overview of the characters determining the file type:
image:./Process_states.png[350,350,role="related thumb right"]
NOTE: **d**rwxrwxr-x 4 zeus zeus 4096 Οκτ 14 20:24 install
* the process is *"created"*.
* After that the process scheduler assigns it the *"waiting"* state. .File types in a long list
* While the process is *"waiting"*, it waits for the scheduler to do a so-called context switch. [options="header,footer"]
* The context switch loads the process into the processor and changes the state to *"running"* while the previously *"running"* process is stored in a *"waiting"* state. |=======================
* If a process in the *"running"* state needs to wait for a resource, it is assigned the *"blocked"* state. |Symbol| Meaning
* The process state is changed back to *"waiting"* when the process no longer needs to wait (in a blocked state). |-| Regular file
* Once the process *finishes execution*, or is *terminated* by the operating system, it is no longer needed. |d| Directory
* The process is *removed instantly* or is moved to the *"terminated"* state. |l| Link
* When removed, it just waits to be *removed from main memory*. |c| Special file
|s| Socket
|p| Named pipe
-- |b| Block device
|=======================
=== Inter-process communication NOTE: -**rw-**rw-r-- 1 zeus zeus 1517 Οκτ 23 21:55 INSTALL.md
When processes need to communicate with each other they must share parts of their address spaces or use other forms of inter-process communication (IPC). ==== Access rights
* For instance in a shell pipeline, the output of the first process need to pass to the second one. .Access rights
* another example is a task that can be decomposed into cooperating but partially independent processes which can run at once [options="header,footer"]
** (i.e., using concurrency, or true parallelism - the latter model is a particular case of concurrent execution and is feasible whenever enough CPU cores are available for all the processes that are ready to run). |=======================
|Code| Meaning
NOTE: It is even possible for two or more processes to be running on different machines that may run different operating system (OS), therefore some mechanisms for communication and synchronization (called communications protocols for distributed computing) are needed (e.g., the *Message Passing Interface, often simply called MPI*). |0 or -|The access right that is supposed to be on this place is not granted.
|4 or r|read access is granted to the user category defined in this place
|2 or w|write permission is granted to the user category defined in this place
==== communication between processes |1 or x|execute permission is granted to the user category defined in this place
|=======================
Processes can communicate with each other through:
* Shared Memory ==== User group codes
* Message passing
.User group codes
[options="header,footer"]
[.float-group] |=======================
-- |Code| Meaning|
[.right] |u| user permissions|-**rw-**rw-r--
image:./1-76.png[350,350,role="related thumb right"] |g| group permissions|-rw-**rw-**r--
[.left] |o| permissions for others|-rw-rw-**rw-**
image:./2-50.png[350,350,role="related thumb left"] |=======================
--
footnote:[https://www.geeksforgeeks.org/inter-process-communication-ipc/[^]] ==== Exercises
[source,bash]
----
touch example
chmod 400 example
ls -l example
chmod 500 example
ls -l example
chmod 600 example
ls -l example
chmod 644 example
ls -l example
chmod 660 example
ls -l example
chmod 700 example
ls -l example
chmod 755 example
ls -l example
chmod 775 example
ls -l example
ls -l example
chmod 777 example
ls -l example
----
:hardbreaks:
{empty} +
{empty} +
{empty}
:!hardbreaks:

Loading…
Cancel
Save