Process and Scheduled Tasks

Source: Internet
Author: User
Tags network function save file pkill

Concept of the process:

In the Linux system, all commands have operation or operation permissions, the same command for different users have different permissions, these permissions belong to the file's property information. So we probably know that in a Linux system, when an event is triggered, the system defines him as a process.

Functions of the kernel: process management, file system, network function, memory management, driver, security

Full function etc.

Process: A copy of a running program that is a collection of instructions that is loaded into memory

Process id,pid number is used to mark individual processes

UID, GID, and selinux contexts determine access and access to the file system,

Typically inherit from the user who executes the process

Existence life cycle

Task Struct:linux data structure format for kernel store process information

Task List: A list of task structs consisting of multiple tasks

Process creation:

Init: First Process

Parent-child Relationship

Process: all created by its parent process, CoW

Fork (), Clone ()


Depending on the relationship between the process and the system terminal, the process can be divided into: daemon and foreground process

Daemon: A process initiated during system boot, that is, a process that is not related to a terminal.

Foreground process: Related to the terminal, through the terminal startup process, it is important to note that the front-end process can also be sent to the background,

The state of the process in the process of being dispatched by the kernel can also be divided into several different types: Run state,

Ready state,

Sleep state: Sleep can be interrupted

Non-terminal sleep: Usually referred to as IO blocking

Wait for IO to meet before it can continue running

Zombie State: Ghosts of ghosts, can not find a home, the father process does not collect

The body or the parent process is dead.

Stop state: Stopped cannot be scheduled and run

Process priority:

System priority: The smaller the number, the higher the priority

0-139 (centos4,5)

Each has 140 run queues and an expiration queue

0-98,99 (CENTOS6)

Real-time Priority: 99-0: Highest value Maximum priority

Nice value: 20 to 19, corresponding to system priority 100-139 or 99

Big O: The relationship between time complexity, timing, and scale

O (1), O (Logn), O (n) linear, O (n^2) parabolic, O (2^n)

Classification of processes:

Cpu-bound:cpu intensive, non-interactive

Io-bound:io intensive, interactive

Linux system Status viewing and management tools: Pstree, PS, Pidof,

Pgrep, Top, htop, glance, Pmap, Vmstat, Dstat, Kill,

Pkill, job, BG, FG, Nohup

Pstree command:

Pstree-display a tree of processes

Ps:process State

Ps-report a snapshot of the current processes

Information about each process in the Linux system is stored in the/proc/pid directory

In each of the documents

Process related commands: Top pstree PS pidof pgrep pkill htop glances pmap vmstat dstat Iostat SAR

Kill Job BG FG etc

PS: View information about the system

Apply PS to view process information

PS [OPTION] ...

Three options are supported:

UNIX options such as-a-e

BSD options such as a

GNU options such as--help

Options: Default display of processes in the current terminal

A option includes all processes in the terminal

The x option includes a process that does not link the terminal

The U option displays information about the process owner

The F option shows the parent process of the process

K|--sort attributes to sort attributes

O Properties ... option to display customized information

PID, Comm,%cpu,%mem, state, TTY, Euser, Ruser

Commonly used combination methods:

1.PS-EF displays information for all processes with complete information

2.ps aux

3.ps Axo

PSR: CPU currently running on the process

PRI: Priority of the current process

NI: Displays the nice value of the current process


Uptime

Displays the current time, the time the system was started, the current number of people on the line, the system level

Average Load (1, 5, 10 min load, generally no more than 1)

Average system load:

Average number of processes running in a queue during a specific time interval

Typically, the current number of active processes per CPU core is not greater than 3, then the system

Performance is good. If the number of tasks per CPU core is greater than 5, then this

Serious problem with host performance

If the Linux host is a 1 dual-core CPU, when load Average is 6

Time to show that the machine has been fully used


Process Management tools:

Top

OP: There are many built-in commands:

Sort:

P: As percentage of CPU occupied,%cpu

M: Occupy memory percentage,%MEM

T: Cumulative CPU Duration, time+

The first message shows:

Uptime information: l command

Tasks and CPU information: T command

CPU Display: 1 (digital)

Memory Information: M command

Exit Command: Q

Modify Refresh time interval: s

Terminates the specified process: K

Save File: W

Top command

US: User space

SY: Kernel space

NI: adjust nice time

ID: Idle

WA: Waiting for IO time

Hi: Hard Interrupt

Si: Soft interrupt (mode switch)

ST: time the virtual machine stole

-D #: Specifies the refresh interval, which defaults to 3 seconds

-B: Show All Processes all

-N #: Refresh many times after exiting



Some interactive commands supported by the Htop interface:

Htop command: Need to install from Fedora-epel source

Http://172.16.0.1/fedora-epel/7/x86_64

Options:

-D #: Specify the delay time;

-U UserName: Displays only the processes of the specified user

-S Colume: Sorting in the specified field

Sub-command:

S: Track system calls for selected processes

L: Displays the list of files opened by the selected process

A: Binds the selected process to a specified CPU core

T: Show Process Tree

Memory Tools


Vmstat command: Virtual memory information

Vmstat [Options] [delay [count]]

Vmstat 2 5

Procs:

R: Number of processes that can run (running or waiting to run), and the number of cores

B: Number of processes in non-interruptible sleep state (length of blocked queue)

Memory

SWPD: Total amount of swap memory used

Free: Total Idle physical memory

Buffer: The total amount of memory used for buffer

Cache: The total amount of memory used for the cache

Swap

SI: Data rate for swapping into memory from disk (KB/S)

So: Data rate from memory swap to disk (KB/S)

Io:

BI: The rate at which data is read from the block device to the system (KB/S)

Bo: The rate at which data is saved to a block device

System

In:interrupts interrupt rate, including clock

Cs:context Switch Process Switching rate

Cpu:

Us:time spent running Non-kernel code

Sy:time spent running kernel code

Id:time spent idle. Before Linux 2.5.41, including io-wait time.

Wa:time spent waiting for IO. 2.5.41 before, including in Idle.

St:time stolen from a virtual machine. 2.6.11 ago, unknown.

Options:

-S: Show memory statistics

Iostat:

Statistics CPU and device IO information

Example: Iostat 1 10

PMAP command: Memory mappings for processes

PMAP [options] pid [...]

-X: Display detailed format information

Example: Pmap 1

Another implementation:

Cat/proc/pid/maps


System Monitoring tool: Glaces

Glaces: is an open-source command system monitoring tool for LINUX,BSD, which is developed using the Python language to monitor CPU, load, memory, disk IO, network traffic, file system, system temperature and other information

Glaces:

Common options:

-B: Display nic data rate in bytes

-D: Turn off the disk I/O module

-f/path/to/somefile: Setting the input file location

-O {html| CSV}: Output format

-M: Disable Mount Module

-N: Disable network module

-T #: Delay time interval

-1: Each CPU related data is displayed separately

System Monitoring Tools

Run the glances command in C/s mode

Server mode:

Glances-s-B ipaddr

IPADDR: Indicates which address of the listening machine

Client mode:

Glances-c ipaddr

IPADDR: Server-side address to connect to

Dstat Command: System resource statistics instead of Vmstat,iostat

Dstat [-AFV] [options:] [Delay [Count]]

-C: Display CPU-related information

-C #,#,..., Total

-D: Show disk-related information

-D Total,sda,sdb,...

-G: Display page related statistics

-M: Display Memory related statistics

-N: Display network-related statistics

-P: Show process-related statistics

-R: Displays statistics related to IO requests

-S: Show swapped related statistics

At task

Package: at

At command: at [option] Time

Common options:

-V Displays version information:

-L: Lists jobs waiting to be run in the specified queue; equivalent to ATQ

-D: Deletes the specified job; equivalent to ATRM

-C: View specific job Tasks

-f/path/from/somefile: Reading a task from a specified file

-M: When the task is completed, the user will be sent a message, even if there is no standard output

Note: standard output and errors in the results of the job execution command are notified to the relevant user by mail

Time: Define when to do at this task

hh:mm [YYYY-MM-DD]

Noon, Midnight, teatime (4pm)

Tomorrow

Now+#{minutes,hours,days, or weeks}

At time format

hh:mm 02:00

In today's hh:mm, if that moment is over, then tomorrow is the time to perform the task.

hh:mm YYYY-MM-DD 02:00 2016-09-20

Specify the task at a particular time of day of the month of the year

HH:MM[AM|PM] [Month] [Date]

04PM March 17

17:20 tomorrow

HH:MM[AM|PM] + number [Minutes|hours|days|weeks]

Add a few more hours to the task at a certain point in time

Now + 5 minutes

rax02pm + 3 days

How the at task is executed:

1) Interactive 2) input redirection 3) at–f file

Dependency and ATD Service, need to start to implement at task

The at queue is stored in the/var/spool/at directory

/etc/at. {Allow,deny} Controls whether the user can perform an at task

Whitelist:/etc/at.allow does not exist by default, only the user in the file

To execute the AT command

Blacklist:/etc/at.deny default, deny user execution in this file

At command, and users who are not in the At.deny file can execute

If none of the two files exist, only root can perform an at command


Recurring Task Scheduler Cron

Recurring Task Scheduler: Cron

Related packages:

Cronie: Main package, providing Crond daemon and related auxiliary tools

Cronie-anacron:cronie Supplement for monitoring Cronie

Operations, such as tasks in Cronie that have not worked in the past.

Run, Anacron will then start this task

Crontabs: Includes centos to provide system maintenance tasks

Scheduled Tasks

Make sure that the Crond daemon is in a running state:

CentOS 7:

Systemctl Status Crond

CentOS 6:

Service Crond Status

Schedule recurring tasks to be submitted to Crond and run automatically at specified times

System Cron Task: system maintenance Job

/etc/crontab

User Cron Task:

crontab command

LOG:/var/log/cron

Scheduled Tasks

Time notation:

(1) Specific values

A value in the range of valid values for a given point in time

(2) *

All values in the range of valid values at a given point in time

Say "every ..."

(3) Discrete value

#,#,#

(4) Continuous value

#-#

(5) in the specified time range, define the step size

/#: #即为步长

Scheduled Tasks

Planned tasks for the system:

/etc/crontab

/etc/cron.d/configuration file

/etc/cron.hourly/Script

/etc/cron.daily/Script

/etc/cron.weekly/Script

/etc/cron.monthly/Script

Anacron system

Tasks that Cron does not run when you run the computer shutdown CentOS6 later versions

Cancel Anacron service, managed by Crond service

For laptops, desktops, workstations, occasionally shut down servers and their

It doesn't always turn on the system is very important to be useful

Configuration file:/etc/anacrontab, responsible for executing/etc/cron.daily

System tasks in/etc/cron.weekly/etc/cron.monthly.

Field 1: If these tasks are not running in these days ...

Field 2: Wait so many minutes after rebooting to run it

Field 3: Task recognizer, identifying in the log file

Field 4: Tasks to perform

Executed by/etc/cron.hourly/0anacron

Update the/var/spool/anacron/cron.daily file when you perform a task

The time stamp


CentOS6 use/etc/cron.daily/tmpwatch to purge temporary files periodically

CentOS7 using Systemd-tmpfiles-setup service to implement

Configuration file:

/etc/tmpfiles.d/*.conf

/run/tmpfiles.d/*.conf

/usr/lib/tmpfiles/*.conf

/usr/lib/tmpfiles.d/tmp.conf

D/tmp 1777 root root 10d

D/var/tmp 1777 root root 30d

Command:

Systemd-tmpfiles–clean|remove|create ConfigFile

User cron:

crontab command definition, each user has a dedicated cron task file:

/var/spool/cron/username

crontab command:

crontab [-u user] [-l |-r |-e] [-I.]

-L: Lists all tasks;

-E: Editing tasks;

-R: Remove All Tasks;

-I: Use with-r to remove specified tasks in interactive mode

-U User: Only root can run, specify User management cron task

To control user execution of Scheduled tasks:

/etc/cron. {Allow,deny}


At and Crontab

Disposable jobs using at

Repetitive jobs using crontab

Scheduled Tasks

Note: standard output and errors for running results are notified to the relevant user by mail

(1) COMMAND >/dev/null

(2) COMMAND &>/dev/null

For cron tasks,% has a special purpose, and if you want to use% in a command,

You need to escape, put% in single quotes, you don't have to escape




Process and Scheduled Tasks

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.