Introduction to 12 process management commands

WBOY
Release: 2016-07-25 08:46:56
Original
1093 people have browsed it
The executing program is called a process. When the program is stored in the storage as an executable file and runs, each process will be dynamically allocated system resources, memory, security attributes and related status. Multiple processes can be associated with the same program and execute simultaneously without interfering with each other. The operating system effectively manages and tracks all running processes.
l In order to manage these processes, users should be able to:
l View all running processes
l View resources consumed by processes
l Locate individual processes and perform specified operations on them
l Change the priority of a process
l Kill the specified process
l Limit the system resources available to the process, etc.
Linux provides many commands to allow users to efficiently control the above operations. Next, let’s explain them one by one. ps is the most basic command in Linux to browse the processes in the system. It can list the processes running in the system, including process number, command, CPU usage, memory usage, etc. The following options provide more useful information.
 ps -a - List all running/active processes
ps -ef |grep - List required processes
ps -aux - Display process information, including none Terminal (x) and processes for users (u): such as USER, PID, %CPU, %MEM, etc.
2. pstreelinux
In linux, each process is created by its parent process . This command displays processes visually, showing the relationships between processes by displaying a tree diagram of the processes. If a pid is specified, the root of the tree is the pid, otherwise it will be init(pid: 1).
3.top
‘top’ is a more useful command that can monitor the resources used by different processes in the system. It provides real-time system status information. The data displayed on the process includes PID, process owner, priority, %CPU, %memory, etc. You can use these displays to indicate resource usage.
4.htop
htop is very similar to top, but htop is an interactive text mode process viewer. It graphically displays the CPU and memory usage and swap usage of each process through text. Use the up and down cursor keys to select a process, F7 and F8 to change the priority, and F9 to kill the process. Htop is not installed by default on the system, so additional installation is required.
5.nice
With the help of nice command, users can set and change the priority of the process. Raising the priority of a process causes the kernel to allocate more CPU time slices to the process. By default, processes are started with priority 0. The process priority can be viewed through the NI (nice value) column displayed by the top command.
  Process priority values ​​range from -20 to 19. The lower the value, the higher the priority.
 nice - Start a program with a given priority value
6.renice
The renice command is similar to the nice command. Use this command to change the priority value of a running process. Note that users can only change the priority value of their own processes.
Renice -n -p - Change the priority value of the specified process
Renice -u -g - Change the priority value of the process by specifying the user and group
7.kill
This Command is used to send a signal to end the process. If a process does not respond to kill commands, it may be necessary to force kill, using the -9 parameter to execute. Note that you must be careful when using forced kill, because the process does not have a chance to clean up the scene, and the writing of the file may not be completed. Killall can come in handy if we don't know the process PID or want to kill the process by name.
 kill
 kill -9
 killall -9 - Kill all processes with the same name
If you use kill, you need to know the process ID number. pkill is a similar command but uses pattern matching such as process name, process owner, etc.
 pkill
8.ulimit
This command is used to control the amount of system resources allocated to the shell and process. It is most useful for system administrators who can manage systems that are heavily used and have performance issues. Limiting resource sizes ensures that important processes continue to run and other processes don't take up too many resources.
 ulimit -a - Displays the resource limits associated with the current user
9.w
w Provides information about the currently logged in user and the processes that are executing. The display information header contains information, such as the current time, system running time, total number of logged in users, and the number of load balancing in the past 1, 5, and 15 minutes.
Based on this user information, users should be careful when terminating processes that do not belong to them.
 who is a similar command that provides the list of currently logged in users, system startup time, run level, etc.
 whoami command outputs the current user ID
10.pgrep
pgrep means "process number global regular matching output". This command scans the currently running process and then lists the matching results to the standard output according to the command matching conditions. Useful for retrieving process IDs by name.
 pgrep -u mint sh
 This command will display the process ID of the user 'mint' and the process name 'sh'.
11.fg , bg
Sometimes, commands take a long time to complete. In this case, we use the 'bg' command to execute the task in the background, and use 'fg' to bring it to the foreground for use.
We can start a program in the background through '&':
find . -name *iso > /tmp/res.txt&
A running program can also be started through "CTRL+Z" " and "bg" command combination to run in the background.
 find . -name *iso > /tmp/res.txt & - start a program
ctrl+z - suspend the currently executing program
bg - transfer the program Run in the background
We can use the 'jobs' command to list all background processes.
 jobs
Use the ‘fg’ command to bring background programs to the foreground for execution.
fg % process id
12.ipcs
ipcs command reports the inter-process communication facility status. (Shared memory, semaphores and message queues)
Use the -p parameter in combination with -m, -s or -q to get the process ID of the relevant inter-process communication.
ipcs -p -m
Lists the creator ID and process ID of the process that recently accessed the shared memory segment.
Summary In summary, these commands can help administrators fix problems and improve performance. Similarly, as an ordinary user, you also need to solve process problems. Therefore, it is effective to be familiar with such a large number of commands and be able to effectively manage the process.
Get LAMP Brothers’ original Linux operation and maintenance engineer video/detailed Linux tutorial for free. For details, please contact the official customer service: http://www.lampbrother.net/linux/



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template