Linux process management and scheduling tasks

Source: Internet
Author: User

First, the process 1. Overview of the process
应用程序(软件):由开发人员使用语言编写;实现用户具体需求
进程:运行软件时产生,用于拿取使用硬件资源  子进程:由单个父进程产生,当父进程结束时,该父进程的子进程全部结束
线程:由进程产生,每个线程各自管理不同的资源内容,合理分配、管理资源
※软件使用过程:开发人员编写→使用软件→产生进程→产生线程→使用硬件资源
2. View the process
(1)pstree    [选项]           //以树形结构显示当前系统进程情况

Options

-a:显示当前系统所有进程-p:显示每个进程对应的PID(进程编号)
(2)ps aux           //简单方式查看进程信息

Options

a:显示当前所有进程信息,包括启用其他用户的进程u:显示运行用户x:显示所运行终端
(3)ps -efl          //详细查看进程和其所属父进程

Options

-e:显示系统内所有进程-l:长格式显示进程信息-f:显示进程的完整信息
USER       PID %CPU %MEM    VSZ        RSS      TTY      STAT   START   TIME   COMMANDroot         1        0.1  0.0           219512  7716       ?        Ss        08:28      0:03    /sbin/initUSER:运行用户PID:进程的标识符TTY:?(本地)、ttyx(1-7)、pts/x(远程)STAT:S(休眠状态)、s(包含子进程)、R(运行中或队列中)、T(停止)、Z(僵死进程;杀死)、X(杀死)、D(不可中断)、+(后台进程)、<(高优先级)、n(低优先级)COMMAND:由哪个程序产生的进程
(4)pgrep [ 选项 ]         //过滤显示指定进程

Options :

-l:显示进程名-U:显示指定用户运行进程-t:显示指定终端

Example :

pgrep -l "log"      //过滤显示所有包含log的进程名pgrep -U root -l        //过滤显示root用户运行的进程pgrep -t tty1 -l        //过滤显示在tty1开启的进程
(5)top          //动态查看进程,q键退出
(6)htop         //人性化动态查看静态

Install Htop:

dhclient -d eth1    //自动获取IPrm -rf /etc/yum.repos.d/*       //删除系统自带YUM源wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo  //下载官方YUM源yum -y install epel-release     //安装第三方YUM源yum -y install htop
2. End Process
(1)kill [-9] PID            //杀死指定PID进程(2)killall [-9] 进程名         //杀死指定进程名(3)pkill [-9] -u 用户名        //杀死所有指定用户开启的进程(4)ps aux | grep 用户名 | awk ‘{print $1}‘ | xargs kill -9     //杀死所有指定用户开启的进程
Ii. Scheduled Tasks 1. One-time Scheduled tasks
(1)at 时间 日期         //创建一次性计划任务  at> 命令  ctrl+d键       //提交
(2)service atd start && chkconfig --level 35 atd on     //启动atd服务并设置为开机自启
(3)atq              //查看未执行的计划任务
(4)atrm [number]            //删除指定计划任务

Note : The created task is saved in the/var/spool/at/directory

2. Recurring Scheduled Tasks
crontab -e [-u 用户]      //创建周期性计划任务

Note : If you do not use the-u option, the current user is created
Format

分       时        日         月          周         命令0-59      0-23      1-31       1-12      1-7         xxx
crontab -l  //查看计划任务
crontab -r  //删除计划任务

Cases:
Restart the server at 0 points per month, 1th

    0 0 1 * *   

Note : The created task is saved in/var/spool/cron/user/directory

Linux process management and scheduling 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.