Our Latest News

Linux development concepts: the difference between programs and processes Interaction between processes

Linux development concepts: the difference between programs and processes Interaction between processes

What is a process?

The code written by the developer we call a program, then the code that will be developed will be run. We call it a process.

Understand: When we run a program, then we call the running program a process.

Concise points

A process is the process of requesting a piece of memory space and putting data into that memory space, the process of requesting data is the smallest resource management unit

A process is a container for threads

The difference between a program and a process

A program is a collection of data and instructions, a static concept, a bunch of code, which can be stored in the system for a long time

Process is the process of running a program, which is a dynamic concept, and it has a life cycle, that is, the process will be destroyed when the program terminates, and will not exist in the system permanently

Interaction between processes

Processes interact with each other through TCP/IP ports

  1. Threads

What is a thread?

A thread is the smallest unit of operation that the operating system can schedule.

It is contained within a process and is the actual unit of operation within the process.

A thread is a single sequential flow of control within a process, and a process can have multiple concurrent threads, each performing a different task in parallel.

Streamlined focus

A thread is a pipeline of a process, used only to execute the program, not to request resources, and is the smallest execution unit of the actual executor of the program

Interaction between threads

Multiple threads share the same block of memory and interact with each other through the shared memory space

  1. The relationship between processes and threads

Example:

When we open a chat software, we open a process; when we open some functions in the software, such as space, swipe, set…, these operations are threads. These operations are threads.

So we can say that “process” includes “thread”, and “thread” is a subset of “process”.

Processes are containers for threads

Example of a factory pipeline:

  1. Summary

Process: an application that is running in the system; once a program is running it is a process; process – the smallest unit of resource allocation.

Thread: the basic unit of the system that allocates processor time resources, or a unit of execution flow within a process that executes independently. Thread – the smallest unit of program execution.

A process has to allocate a large portion of memory, while a thread needs to allocate only a portion of the stack.

A program has at least one process, and a process has at least one thread.

A thread can create and cancel another thread, and multiple threads in the same process can execute concurrently with each other.

II. Parallel, Concurrent, Serial

Concurrency: Multiple tasks appear to be running simultaneously, which is a kind of pseudo-parallelism

Single-core implementation using multichannel techniques

Parallelism: multiple tasks are performed simultaneously

Parallelism can only be achieved with multiple cores, otherwise only concurrency can be achieved (pseudo-parallelism)

Serial: One program runs in its entirety, then the next process runs

IV. Three states of task operation

A process changes its running state continuously during its operation

Usually a running process must have three states: Ready, Running, and Blocking

  1. Ready state (Ready)

The state of a process is called ready when it has been allocated all necessary resources except the CPU and can execute the program as soon as it gets the CPU again,

There may be more than one process in the ready state in a system, and they are usually arranged in a queue, which is called the ready queue.

  1. Running state (Running)

When a process has been granted CPU access and its program is running, it is called running state.

In a single-core operating system, only one process is in the running state, while a multi-core operating system has multiple processes in the running state.

  1. Blocked (sleep)

When a process is executing, it is deprived of cpu operation time by the operating system because it is waiting for a certain event.

There are various reasons for blocking, such as waiting for I/O operations, higher priority tasks taking away CPU privileges, etc.

  1. Transition between the three states of a process

A process is constantly switching from one state to another during its operation

It can be in the ready state and running state many times, or it can be in the blocking state many times, the following figure shows the transition between the three states

Ready state➠➠Running state

A process in the ready state changes from the ready state to the running state when the process scheduler allocates a CPU time slice to it.

Running state ➠➠Ready state

A process in the running state loses CPU access when the allocated time slice is used up, and the running state is changed to the ready state.

Running state➠➠Blocking state

A running process cannot continue to execute because it encounters I/O operations or a higher priority task takes CPU access, so it changes from running state to blocking state.

Blocking state➠➠Ready state

A process in the blocking state is transferred from the blocking state to the ready state if what it was waiting for has been processed.

IV. Two ways of task submission

  1. Synchronization

Synchronization is a communication method in which the sender sends data and waits for the receiver to send back a response before sending the next datagram.

Synchronous means that two programs are running in relation to each other, one thread is blocking and needs to wait, then the other thread is running

  1. Asynchronous

Asynchronous means that the sender sends data and then sends the next datagram without waiting for the receiver to send back a response.

Asynchronous means that the two threads are unrelated and run on their own

  1. Example

Synchronous

❶ If you ask me to go to dinner, I will go to dinner with you as soon as I hear you, and if I don’t hear you, you will keep calling me until I tell you that I hear you, and then we will go to dinner together

❷A phone call is like synchronous, both sides are going on at the same time and you can’t call another person

Asynchronous

❶ You ask me to go to dinner and then go to dinner by yourself, I may go immediately after I get the message, or I may go later

❷Sending a message is like asynchronous, you can send a message to another person after you send a message to one person

V. Process pools

  1. What is a process pool?

A process pool is a resource process, an application of technology that manages the composition of processes.

  1. Why do we need process pools?

When we are busy, there are thousands of tasks that need to be executed, and when we are idle, there may be only a few tasks.

So when thousands of tasks need to be executed, do we need to create thousands of processes?

First of all, it takes time to create processes and time to destroy them.

Secondly, even if thousands of processes are opened, the operating system can’t let them execute at the same time, which will affect the efficiency of the program.

So we can’t open or close processes based on tasks indefinitely. So how do we do it?

  1. The concept of process pool

Define a pool, put a fixed number of processes in it, and when a demand comes, take a process from the pool to process the task

When the process is finished, the process is not closed, but is put back into the process pool to continue waiting for the task

If there are many tasks to be executed and the number of processes in the pool is not enough, the task will have to wait for the previous process to return from executing the task and get a free process to continue execution.

In other words, the number of processes in the pool is fixed, so there are at most a fixed number of processes running at the same time.

This does not increase the scheduling difficulty of the operating system, but also saves the time of switching processes on and off, and can achieve concurrency effect to some extent.

  1. Resource processes

The management process (like a pool) will distribute the work to the idle process to handle.

  1. Management processes

The management process is responsible for creating the resource process, handing over the work to the free resource process, and recycling the resource process that has finished processing the work.

Interaction between resource processes and management processes

How can the management process effectively manage the resource process and assign tasks to the resource process?

Interaction is done through IPC, signals, semaphores, message queues, pipelines, etc.

    GET A FREE QUOTE

    FPGA IC & FULL BOM LIST

    We'd love to

    hear from you

    Highlight multiple sections with this eye-catching call to action style.

      Contact Us

      Exhibition Bay South Squre, Fuhai Bao’an Shenzhen China

      • Sales@ebics.com
      • +86.755.27389663