Linux (vi) __ Process and task control

Source: Internet
Author: User
Tags terminates

One, program, process, thread

1. A program is an ordinary file, a collection of instructions and data, a static entity, and a code that is stored on the peripherals by the programmer. It is "dead", and processes and procedures are "alive".

2. A process is an example of an execution of a program, a running program, and a copy of a program, which is placed on disk and the program is in memory. Each process is assigned an ID number.

Each process corresponds to a parent process, and the parent process can replicate multiple child processes. For example WWW server.

3. A thread is a smaller execution unit than a process, and a process consists of at least one thread. In order for a process to run on multiple CPUs at the same time, it has to be divided into multiple execution streams that are not affected, which are threads.

The process has a separate memory address space, and the thread has no

A thread cannot exist independently, it is created by a process. (Fork under Linux, thread in Java)

Ii. Classification of processes

Depending on the function of the process and the program being run, the process can be divided into two main categories:

? System process: Can perform the management of memory resource allocation and process switching, and the running of the process is not interfered by the user, even the root user cannot intervene the system process.

? User process: A process that is generated by executing a user program, an application, or a system program outside the kernel, which can be run or shut down Under the user's control.

For the user process, but also can be divided into interactive process, batch process and daemon three categories.

? Interactive process: a process initiated by a shell terminal that, during execution, needs to interact with the user and can run in the foreground or in the background.

? Batch process: The process is a collection of processes that are responsible for starting other processes sequentially.

? Daemon: A daemon is a process that runs all the time and is often started when the Linux system starts and terminates when the system shuts down. They are independent of the control terminal and periodically perform certain tasks or wait to handle certain occurrences.

For example, the httpd process, which is running, waits for the user's access. There are also frequently used crond processes, which are similar to the Windows scheduled tasks that can periodically perform certain tasks that the user sets.

Second, PS command- static display of the process performed by the system

The PS command is used to view what is currently being performed in the system, and what the status of their execution is. Can not add any parameters

Show detailed process information

1, ps-a: means to display all the process information of the current terminal.

2. Display process information in user's format.

Ps-u: Displays process information in the user's format.

3. Show background process running parameters:

Ps-x: Displays the parameters that the background process is running.

4. You can use Ps-aux to display comprehensive process information.

Linux Displays the system process command PS, the most commonly used are ps-ef and PS aux.

PS-EF Displays the process in a standard format, with the following format

The contents of each column are as follows
UID//user ID, but output is user name
PID//Process ID
PPID//Parent process ID
C//Percentage of CPU consumed by process
Stime//Process start to present time
TTY//The process runs on that terminal, if it is not related to the terminal, then display? For pts/0, this means that the host process is connected by the network.
CMD//Command name and parameters

PS aux is displayed in BSD format, and its format is as follows

Unlike Ps-ef, there are lists of
User//username
Percentage of CPU%CPU//process occupied
%MEM//Percentage of memory occupied
VSZ//The amount of virtual memory used by the process (KB)
RSS//This process occupies a fixed amount of memory (KB) (number of pages residing in)
STAT//Status of the process
Start//The process is triggered by startup time
Time//When the process actually uses the CPU to run

where the stat status bit common state characters have
D//The dormant state (usually IO process) that cannot be interrupted;
R//is running can be in the queue can be over line;
S//in hibernation;
T//stop or be traced;
W//Enter memory swap (invalid starting from kernel 2.6);
X//Dead process (basic rarely seen);
Z//zombie process;
<//high-priority processes
N//low-priority processes
L//Some pages are locked into memory;
S//leader of the process (under it there are sub-processes);
L//multi-threaded, clone thread (using Clone_thread, similar to NPTL pthreads);
+//process group in the background;

Iv. termination of the process Kill/killall

Terminate a process: kill process Number

Kill 16251: Represents a process that terminates process number 16251.

Kill-9 16251: Because some processes capture certain signals. If the process cannot be terminated directly, the message can be transmitted with "-9". Forced termination

Killall process name to purge processes and process-related child processes

Killall-u username can kill all processes of a user

Five, front and rear desk operation management

    • Foreground job: Occupy command prompt

    • Background job: After startup, release the command prompt, and subsequent operations are completed in the background

Front desk--Backstage:

①ctrl+z: Send the job in the foreground to the backstage, and the job is in stopped state

②command &: Let commands execute in the background

Backstage-Reception

FG Marking

BG keeps the background stop job running

FG to move backstage jobs to the front desk

Jobs View all jobs in the background

VI. dynamic monitoring process top Exit top Press the Q key or CTRL + C key to exit

Top is very similar to the PS command. They are all used to show the process being executed. The biggest difference between top and PS is that top performs a period of time to update a running process.

Exit: Ctrl + C

1. Monitor specific users

Top: Enter this command and press ENTER to see the process being executed.

U: then enter "U", then enter the user name, you can.

2. Terminate the specified process

Top: Enter this command and press ENTER to see the process being executed.

K: Then enter the "K" carriage return and enter the process ID number to end.

3. Specify the time of the system Status update

Top-d 10: Specifies the time for the system update process to be 10 seconds.

14:06:22 Up system time

4 min, how long does the system start?

1 user, how many users are currently logged on to Linux

Load avcragc:0.02, 0.12, 0.07 workload balancing, current system load conditions (full addition of 3 greater than 0.6 means system load tight)

PNS processes: Current number of processes

Sleeping, number of dormant processes

1 running, number of running processes

0 Zombie, number of processes that still occupy memory after the zombie process count process is useless

0 stopped the number of processes in the stopped state

CPU states:0.0% User 0.1% system 0.0% Nice 0.0% iowait 99.8% idle

The state of the CPU idle for the CPU idle state (the bigger the better)

men:255264k av, 39420k used, 215836k free, 0k shrd, 5520k Buff

30632k ACTV, 140k in_d, 292k In_c

Memory usage

255264k av, total amount of memory

39420k used, amount of memory being used

215836k free, amount of idle memory

swap:257032k av, 0k used, 257032k free 19376k Cached

Swap partition (virtual memory) usage

swap:257032k Number of Av,swap partitions (virtual memory)

0k used, number of virtual memory being used

257032k Free Virtual Memory amount

19376k Cached Cache memory

Vii. Task Scheduling commands

Overview:

Task scheduling: Refers to a particular command or program that the system executes at a certain time.

Task Scheduling Classification:

1, the system work: some important work must be carried out in the cycle. such as virus scanning.

2, individual users work: Individual users may want to execute some programs.

Set Task Scheduler file:/etc/crontab

Set up a personal task schedule. Executes the crontab-e command. Then enter the task into the dispatch file

Example: 5 * * * * ls-l/etc/>/tmp/to.txt

Mean five minutes per hour execution ls-l/etc/>/tmp/to.txt command

Use Crontab for task scheduling

1. Set Task Crontab-e

2, every time to perform

Date >/home/mydatal (overwrites the current time to the MyData1 file.) > Write for overwrite)

Date Displays the current time

1) want to perform date >>/home/mydate2 (>> append write) every day 2:00

0 2 * * * Date >>/home/mydate2

2) wish to execute every minute

* * * * * Date >>/home/mydate2

Schedule file Rules:

Field Name Description Range

Minutes of the minute per hour of execution 0-59

Hours per day of the first few hours of execution 0-23

Day of the month of the day of execution 1-31

Monthly calendar year of the month to execute 1-12

Day of the week weekly execution 0-6

Command name to execute command name and its arguments

3, how to dispatch multiple tasks?

1) write multiple tasks directly in CRONTAB-E (advantages: simple; Disadvantages: too much too messy modification inconvenient)

2) can put all the tasks, write to an executable file (Shell programming) recommended

. sh file is a shell file, chmod 744 mytask.sh to make it an executable remember

VI mytask.sh

Date >>/home/mydate2

cp/home/mydate2/root/

: Wq

Crontab-e

* * * * * */root/mytask.sh

4. How to terminate a task

To terminate a task schedule:

Crontab-r: Terminating task scheduling (disabling this command when multitasking is used by multiple users)

Crontab-l: Lists the tasks that are currently scheduled

Linux (vi) __ Process and task control

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.