Process view & current view file size

 

View Linux file directory size:

View the largest folder in the current directory du --max-depth=1 -h

ps 10519

ps  pid

ps ax : show a list of current system processes 

ps aux : Display a detailed list of current system processes and process users

ps ax|less : If the output is too long, you may add a pipeline command less to view the specific process, such as: ps ax|grep XXX (XXX is the process name)

get process id
How the shell gets the process ID:
  ps -A |grep "cmdname"| awk '{print $1}'
  pidof "cmdname"
  pgrep "cmdname"
These three kinds of running results in bash and busybox ash are slightly different,
The first one is exactly the same, but because of the large number of calls to the command, the performance is not good.
 
The second type: pidof can only get the process ID matched by the file name of the program. In ash, for example, pidof "usr/bin/telnetd" and pidof "telnetd" have different results. The former result is empty, but in bash perform the same in both.
 
The third: pgrep has the same effect as 1, because it is a single command, which is much better than the first.

So nanoRC is improved to pgrep.

  

process kill

Terminal/Program Interrupt in HUP 1 Control
INT 2 keyboard insert command (same as Ctrl + C)
QUIT 3 Keyboard interrupt command (same as Ctrl + \)
TERM 15 Program termination command
KILL 9 program's forced termination instruction (violent cut)
CONT 18 Program restart command (restart after STOP(19))
STOP 19 Program stop command (same as Ctrl + Z)

1. Function
The kill command is used to kill a process.

2. Format
kill [ -s signal | -p ] [ -a ] pid ...
kill -l [ signal ]

3. Parameters
-s: Specifies the signal to send.
-p: Analog transmit signal.
-l: Specifies a list of names of signals.
pid: The ID number of the process to abort.
Signal: Indicates a signal.

Description: Process is a very important concept in Linux system. Linux is a multitasking operating system, and there are often multiple processes running on the system at the same time. We don't care how these processes are allocated, or how the kernel manages the allocation of time slices. What we care about is how to control these processes so that they can serve users well.

The Linux operating system includes three different types of processes, each with its own characteristics and attributes. An interactive process is a process started by a shell. Interactive processes can run either in the foreground or in the background. The batch process has no connection with the terminal, it is a sequence of processes. The monitoring process (also known as the system daemon) is a process that is started when the Linux system starts and runs in the background. For example, httpd is the monitoring process of the well-known Apache server. 

The working principle of the kill command is to send a system operation signal and the process identification number of a program to the kernel of the Linux system, and then the system kernel can operate the process specified by the process identification number. For example, in the top command, we see that the system is running many processes, and sometimes it is necessary to use kill to terminate some processes to improve system resources. When explaining the installation and login commands, it was mentioned that the function of multiple virtual consoles in the system is that when a program error causes the system to deadlock, you can switch to other virtual consoles to work and close the program. The command used at this time is kill, because kill is what most internal shell commands can call directly. 

Application example 
(1) Forcibly abort (usually kill) a process with a process ID of 324: 
#kill -9 324 

(2) Removing the deadlock 
of the Linux system Sometimes such a situation occurs in Linux: a program crashes and is in a deadlock state. At this time, it is generally not necessary to restart the computer, and only need to suspend (or close) the problematic program. When kill is in the X-Window interface, the main program (except the crashed program) has generally started normally. Open a terminal at this point and abort the offending program there. For example, if the Mozilla browser program locks up, you can use the kill command to kill all programs that contain the Mozolla browser. First use the top command to find out the PID of the program, and then use the kill command to stop the program: 
#kill -SIGKILL XXX 
where XXX is the process identification number of the program that contains the Mozolla browser. 

(3) Use commands to reclaim memory 
We know that memory is very important to the system, and reclaiming memory can improve system resources. The kill command can promptly stop some "deviant" programs or there is no corresponding program for a long time. For example, using the top command to find a useless (Zombie) process, you can use the following command: 
#kill -9 XXX 
where XXX is the useless process identification number. 

Then use the following command: 
#free 
At this point, you will find that the available memory capacity has increased. 

(4) killall command 

A killall command is also provided under Linux, which can directly use the process name instead of the process identification number, for example: 

# killall -HUP inetd 

*The safest way to kill a process is to simply use the kill command, with no modifiers and no flags. 

First use the ps -ef command to determine the PID of the process to kill, then enter the following command: 

# kill -pid 

Note: The standard kill command usually does the trick. Terminate the process in question and release the process' resources to the system. However, if a process starts a child process, and only kills the parent process, the child process is still running and thus still consuming resources. To prevent these so called "zombie processes", make sure to kill all of its child processes before killing the parent process. 

 

-------------------------------------------------------------------------------- 

* Determine the PID or PPID of the process to kill 

# ps -ef | grep httpd 
-------------------------------------------------------- ------------------------------------- 


* End the process gracefully 

# kill -l PID 

The -l option tells the kill command to end the process as if the user who started the process was logged out. When this option is used, the kill command also attempts to kill any child processes left behind. But this command doesn't always work -- it might still be necessary to kill the child process manually first, and then kill the parent process. 
-------------------------------------------------- ------------------------------ 


*TERM signal 

Send a TERM signal to the parent process, trying to kill it and its children. 

# kill -TERM PPID 
-------------------------------------------------------------------------------- 


*killall命令 

The killall command kills all processes within the same process group. It allows to specify the name of the process to be terminated instead of the PID. 

# killall httpd 
----------------------------------------------- --------------------------------- 


*Stop and restart the process 

Sometimes you just want to simply stop and restart the process. as follows: 

# kill -HUP PID 

This command causes Linux's graceful execution process to shut down and then restart immediately. This command is very convenient when configuring the application, and can be executed when the process needs to be restarted after modifying the configuration file. ? ? ? ?
-------------------------------------------------- ------------------------------ 


*lore kill -9 PID 

Agree kill -s SIGKILL 

This powerful and dangerous command forces the process to terminate abruptly while it is running, and the process cannot clean itself up after it ends. The harm is that the system resources cannot be released normally, which is generally not recommended unless other methods are ineffective. 

When using this command, be sure to confirm with ps -ef that there are no zombie processes left. Zombie processes can only be eliminated by killing the parent process. If the zombie process is adopted by init, the problem is more serious. Killing the init process means shutting down the system. 

If there is a zombie process in the system, and its parent process is init, and the zombie process consumes a lot of system resources, then at some point the machine needs to be restarted to clear the process table.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325216839&siteId=291194637