Introduction to 12 Linux Process Management commands

Source: Internet
Author: User
Tags pkill

Introduction to 12 Linux Process Management commands
GuideThe program in execution is called a process. When a program can execute files stored in the storage and run, each process is dynamically allocated system resources, memory, security attributes, and related states. Multiple processes can be associated with the same program without interfering with each other. The operating system will effectively manage and track all running processes.

To manage these processes, you should be able:

● View all running processes

● View Process Resource Consumption

● Locate individual processes and perform specified operations on them

● Change process priority

● Kill a specified process

● Restrict available system resources of processes

Linux provides many commands to allow users to efficiently control the above operations. Next, let's explain it one by one.

1. ps

'Ps' is the most basic process command in Linux. Lists processes running in the system, including process numbers, commands, CPU usage, and memory usage. The following options can be used to obtain more useful messages.

Ps-a-list all running/activated Processes

Ps-ef | grep-list required processes
Ps-aux-displays process information, including non-terminal (x) and USER (u) processes, such as USER, PID, % CPU, and % MEM.
2. pstree

In linux, every process is created by its parent process. This command visually displays processes and displays the relationship between processes by displaying a tree chart of 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 resources used by different processes in the system. It provides real-time system status information. The displayed process data includes PID, process owner, priority, % CPU, and % memory. You can use these displays to indicate resource usage.

4. htop

Htop is similar to top, but htop is a process viewer in interactive text mode. It visually displays the CPU and memory usage and swap usage of each process. Use the up/down cursor key to select a process. F7 and F8 change the priority and F9 kill the process. Htop is not installed by default, so additional installation is required.

5. nice

With the help of the nice command, you can set and change the priority of a process. To increase the priority of a process, the kernel will allocate more CPU time slices to the process. By default, processes are started with a priority of 0. The process priority can be viewed in the NI (nice value) column displayed by the top command.

The process priority value ranges from-20 to 19. The lower the value, the higher the priority.

Nice <priority> <process name>-start a program with the given priority

In the preceding command example, we can see that the 'top' command obtains the priority value of-3.

6. renice

The renice command is similar to the nice command. Use this command to change the priority of running processes. Note that users can only change the priority of their own processes.

Renice-n-p-changes the priority of a specified process

The process priority value of 3806 with the initial priority value 0 has changed to 4.

Renice-u-g-change process priority by specifying users and groups

In the preceding example, the priority of all processes whose user is 'mint' is changed to '-3 '.

7. kill

This command is used to send a signal to end the process. If a process does not respond to the kill command, it may need to force the kill and run the-9 parameter. Note that you must be careful when using force-killing, because the process does not have the time to clean up the site, maybe the file writing is not completed. Killall can be used if we do not know the process PID or intend to kill the process by name.

kill<pid>
kill-9<pid>
Killall-9-kill all processes with the same name

If you use kill, you need to know the process ID. Pkill is a similar command, but it uses pattern matching, such as process name and process owner.

Pkill <process name>

8. ulimit

This command is used to control the distribution of system resources in shell and process. It is most useful for system administrators to manage systems with severe usage and performance problems. Limiting the resource size can ensure that important processes run continuously, and other processes do not occupy excessive resources.

Ulimit-a-display the resource limits associated with the current user

-F: Maximum File Size

-V: Maximum virtual memory size (KB)

-N: increase the maximum number of file descriptors.

-H: Change and report Hard Limits

-S: Soft Limits on changes and reports

Go to the ulimit man page to get more options.

9. w

W provides information about the user currently logged on and the process being executed. The display information header contains information, such as the current time, system running duration, total number of logged-on users, number of Server Load balancer instances in the past 1, 5, and 15 minutes.

Based on the user information, you must be careful when terminating processes that do not belong to them.

The who command provides a list of currently logged on users, system startup time, and running level.

Whoami command output current user ID

10. pgrep

Pgrep indicates "process number Global Regular Expression matching output ". This command scans the currently running process and lists matching results to the standard output according to command matching conditions. It is useful for searching process numbers by name.

pgrep-umintsh

This command will display the process ID whose user is 'mint' and whose name is 'sh.

11. fg, bg

Sometimes, the command takes a long time to complete. In this case, we can run the 'bg 'command in the background, while 'fg' can be used in the foreground.

We can start a program in the background through:

find.-name*iso>/tmp/res.txt&

A running program can also be run in the background by combining the "CTRL + Z" and "bg" commands.

Find.-name * iso>/tmp/res.txt &-start a program
Ctrl + z-suspend the current execution Program
Bg-put the program in the background to run

We can use the 'job' command to list all background processes.

jobs

You can use the 'fg' command to transfer the background program to the foreground for execution.

Fg % process id

12. ipcs

The ipcs Command reports the status of inter-process communication facilities. (Shared memory, semaphore and Message Queue)

You can use the-p Parameter in combination with-m,-s, or-q to obtain the ID of the processes that communicate with each other.

ipcs-p-m

The following screen lists the IDs and process IDs of the creators who recently accessed the shared memory segments.

Summary

In short, these commands can help administrators fix problems and improve performance. As a common user, you also need to solve problems in the process. Therefore, it is effective to be familiar with so many commands to effectively manage processes.

From: http:// OS .51cto.com/art/201507/485042.htm

Address: http://www.linuxprobe.com/12linux-process-commands.html


Related Article

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.