Linux how to view and process control process

Linux how to view and process control process

Introduction: The program stored in the external storage medium is a static set of machine executable code and data (e.g., hard disk), and the process is performed in a dynamic state of a computer program in the CPU and memory. In the Linux system, after each program start you can create one or more processes. For example, the httpd program to provide Web services, when there are a large number of users simultaneously access the Web page, httpd program may create multiple processes to provide services.

A: view and control processes

Different tools can use the command to view the status of the process from a different perspective.

1, a static view of process statistics --ps

ps aux ps -elf

a: displays all process information in the current terminal

u: user-based format of the output process information

x: Displays the current user process information in all terminals

-e: show all processes within the information system

-l: long format process information

-f: use the full format process information

Linux how to view and process control process

The first line of the list fields meanings indicated:

USER: Start user account name of the process

PID: ID number of the process, is unique in the current system

TTY: The process runs on which terminal. "?" Unknown table or no terminal

STAT: shows the current state of the process, such as S (sleep), R (run), Z (dead) <(high priority), N (lower priority), s (the parent process), + (foreground process ). Of the process is in a state of dead should be manually terminated.

START: Start time of the process

TIME: The process CPU time

COMMAND: name of the command to start the process

% CPU: The percentage of CPU usage

The percentage of memory usage:% MEM

VSZ: occupancy size of the virtual memory (swap space)

RSS: occupy resident memory size (physical memory)

Linux how to view and process control process

A larger number of processes running on the system, you need to query a particular process information, can be combined with pipeline operations and grep command filters. Such as: filter out include "bash" process information

Linux how to view and process control process

2, view the dynamic process information --top

The top command terminal display full-screen interactive interface to the process of ranking in the current, time tracking including CPU, memory and other system resources occupancy, refreshed every three seconds by default. It acts as task manager for Windows systems.

Linux how to view and process control process

3, the query process information --pgrep

​ pgrep 是用来查询特定进程信息的专用工具,使用pgrep 可以根据进程的名称、运行该进程的用户、进程所在的终端等多种属性查询特定进程的PID号。

结合“-l” 可同时输出对应的进程名。例如: 查询进程名中包含“log” 的进程及PID号

Linux how to view and process control process

4、查看进程树——pstree

​ pstree命令可以输出linux系统中各进程的树形结构,更加直观地判断各进程之间的相互关系(父、子进程)。

​ pstree -aup

a : 列出完整的命令信息

u:列出对应的用户名

p: 同时列出对应的PID号

Linux how to view and process control process

查看指定用户的进程树结构,只要指定用户名作为参数即可。前提这个用户是可以被登录的

Linux how to view and process control process

二 :控制进程

1、启动进程

在Linux中,可以由用户手工启动或按预定计划调度启动新的进程。

(1)手工启动进程

​ 由用户手工输入命令或可执行程序的路径,可以至少启动一个进程。可分为前台启动和后台启动。进程在前台运行时必须等到该进程执行结束并退出才能继续输入其他命令,大多数命令都是在前台启动运行。 启动后台进程需要使用“&”操作符,放在执行命令的最后,进程启动会直接放入后台运行,不占用前台命令操作界面。

​ 例如:把目录/mnt/packages 复制到/opt/ 下,由于需要复制的数据较多,因此可结合“&” 符号将复制操作放到后台运行,以便可以继续执行其他命令操作。

Linux how to view and process control process

(2)调度启动进程

​ 进程的调度启动可以通过at、crontab 命令进行设置,at 命令用于设置一次性计划任务,crontab 用于设置周期性运行的计划任务。

at 一次性任务设置

​ 只在指定的时间点执行一次,前提是对应的系统服务atd必须已经运行。注意:计划执行任务的时间、日期必须安排在当前系统的时刻之后,否则无法正确设置计划任务。

Linux how to view and process control process

删除第2条at计划任务:atrm 2

crontab周期性任务设置

Use the crontab command to set the schedules can be performed repeatedly at preset cycles, greatly reducing operational settings repetitive system administration tasks, provide crontab tools, systems and service crond configuration file / etc / crontab by the package cronie. Provided that the corresponding system crond service must be running.

First of all you need to know which side profile

Linux how to view and process control process

Linux how to view and process control process

-e: Edit list of scheduled tasks

-u: Specifies the management of scheduled tasks belong to which users own default for the current user, usually only the root user has permission to use this option

-l: displays a list of scheduled tasks

-r: delete the scheduled task

Crontab configuration format scheduled tasks, the five time fields followed by minute, hour, date, month, week.

Example:

1, performed once every minute myCommand

* * * * * myCommand

2, 3 hour and 10 minutes of execution myCommand

3,10 * * * * myCommand

3, 3 and 15 minutes every day 8:00 to 11:00 is performed

3,15 8-11 */2 * * myCommand

4, every night 21:30 smb restart

30 21 * * * /etc/init.d/smb restart

5, a day every 30 minutes between 18:00 and 23:00 restart smb

0,30 18-23 * * * /etc/init.d/smb restart

6, every hour restart smb

* */1 * * * /etc/init.d/smb restart

7, smb restart every hour between 23:00 to 7:00

* 23-7/1 * * * /etc/init.d/smb restart

Guess you like

Origin blog.51cto.com/14557920/2450250