11. Process Control Theory

Source: Internet
Author: User
Tags mutex wrapper

11. Process Control Theory

Process: A process is a run of an application with a certain independent function. A program that is not running is not called a process, only a program that is running will produce a process.

Characteristics of the process:

    1. Dynamic nature
    2. Concurrency of
    3. Independence
    4. of Asynchrony

Status of the process:

When we run a program, the program is in the ready state. Because the program requires resources, such as memory, hard disk space, and so on. So the CPU issues an I/O request. If a program is running at this point, these resources are being used. Will not be satisfied, it will cause the process to go into a blocking state. When the resource request is satisfied, it enters the ready state again. Waiting for the CPU to dispatch, in the process of execution, if a process in the system specified within a time slice is not able to execute, he will again into the ready state, again waiting for CPU scheduling. So loop, know that the program runs out.

?

Process ID:

Process ID (PID): The system gives each process a unique identifier, which is a number.

The ID of the parent process (PPID).

The user ID (UID) of the startup process.

?

?

Mutex for process:

A process mutex is when a resource is used by a number of processes, but the resource allows at most one process at a time to make

, the other process must wait until the resource is freed by the resource being consumed.

?

Critical resources:

In the operating system, at some point, only a single process is allowed access to a resource called a critical resource.

?

Critical section:

The program code that accesses critical resources in a process is called a critical section. In order to achieve mutually exclusive access to critical resources, the processes should be guaranteed to enter the respective critical areas.

?

Synchronization of Processes:

A process in which a group of processes executes in a certain order is called inter-process synchronization. This set of processes with a synchronous relationship is called a collaborative process, most notably producer and consumer processes.

?

Scheduling of processes:

According to a certain algorithm, from a set of processes to run to choose one to occupy the CPU operation.

?

Common scheduling algorithms:

    1. First come first serve
    2. Short process First
    3. High priority priority
    4. Time Slice Rotation method

Timing of scheduling:

    1. Preemptive scheduling
    2. Non-preemptive scheduling

?

?

Deadlock:

Multiple processes are deadlocked as a result of competing resources, resulting in the inability of these processes to proceed forward.

?

Let's look at the function that gets the process:

The function that gets the process ID is: getpid.

View the information for this function: Man 2 getpid:

NAME

Getpid, Getppid-get process identification

?

Synopsis

#include <sys/types.h>

#include <unistd.h>

?

pid_t getpid (void);

pid_t getppid (void);

?

DESCRIPTION

Getpid () returns the process ID of the calling process. (This is often

Used by routines that generate unique temporary filenames.)

?

Getppid () returns the process ID of the the parent of the calling process.

?

ERRORS

These functions is always successful.

?

Conforming to

posix.1-2001, 4.3BSD, SVr4.

?

NOTES

Since glibc version 2.3.4, the glibc wrapper function for Getpid ()

Caches PIDs, so as-avoid additional system calls when a process

Calls Getpid () repeatedly. Normally this caching is invisible

Correct operation relies on support in the wrapper functions for

Fork (2), Vfork (2), and Clone (2): If an application bypasses the GLIBC

Wrappers for these system calls by using Syscall (2)

Getpid () in the child would return the wrong value (to be precise:it

Would return the PID of the parent process). See also clones (2) for dis-

Cussion of a case where getpid () could return the wrong value even when

Invoking Clone (2) via the glibc wrapper function.

?

See ALSO

Clone (2), fork (2), Kill (2), EXEC (3), Mkstemp (3), Tempnam (3), tmp-

File (3), Tmpnam (3), credentials (7)

?

Colophon

This page was part of release 3.22 of the Linux man-pages project. A

Description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Gets the process ID of the function getpid. The return value of the function is the ID of the process that called the function. Required Header files:

<sys/types.h> <unistd.h>

The function has no arguments. The return value is the ID of the process that called the function.

Example GETPID.C:

#include <sys/types.h>

#include <unistd.h>

#include <stdio.h>

?

void Main () {

???? int id = 0;

???? id = getpid ();

???? printf ("process ' s ID%d\n", id);

}

?

Results of the operation:

Above, the generated getpid is a program, and when we do not go to run, he is a program. When we run, he becomes a process. The ID of the process is changing all the times.

?

?

?

?

?

11. Process Control Theory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.