Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux - Common process the command     - RedHat Linux 6.5 Enterprise Edition installation Redis 3.0.3 (Database)

- Example of use WebSocket (Programming)

- Java Prototype Pattern (Programming)

- Experience PHP 7.0 on CentOS 7.x / Fedora 21 (Server)

- Use preseed script to install Ubuntu 14.04 (Linux)

- Java call by value and by reference (Programming)

- Hibernate Performance Optimization of reusing SessionFactory (Programming)

- ASP.NET 5 is connected with the Redis server on the Linux platform (Server)

- SpringMVC the use of interceptors (Programming)

- Java and C / C ++ data conversion when network communication (Programming)

- Oracle 12c PDB Analysis (Database)

- Linux kernel RCU (Read Copy Update) lock Brief - prequel (Linux)

- Understand the security restore accidentally deleted critical system files (Linux)

- There are more than one server, there is reason to try cloud operating system (Server)

- Linux environment installation of rvm and ruby (Linux)

- FreeBSD install Gnome 3 Desktop (Linux)

- Samhain: Powerful intrusion detection system under Linux (Linux)

- Use SecureCRT to transfer files between local and remote hosts (Linux)

- Loop arrays in C language is not easy to find a bug (Programming)

- linux network security experience (Linux)

 
         
  Linux - Common process the command
     
  Add Date : 2017-04-13      
         
         
         
  1. Process Monitor command (ps):
  To monitor and control the process, we must first understand the situation of the current process, which is the need to review the current process, and ps command is the most basic but also very powerful process view command. Use this command can determine which process is running and running the state, the process is finished, there is no rigid process, which process takes up too many resources and so on. In short most of the information can all be obtained by executing this command.
  ps command has many command-line options and parameters, but only two of our most common form, where the first is given and their associated options and arguments meanings:
Option Description
a display terminal all processes, including processes of other users.
u user-based format to display program status.
x display all programs, not to the end to distinguish.
-e show all processes.
o Then specify the columns to the output, such as user, pid, etc., separated by a comma between multiple columns.
-p Pid later followed by a group list, separated by commas, the command will only output data of these pid.

  /> Ps aux

  root 1 0.0 0.1 2828 1400? Ss 09:51 0:02 / sbin / init
  root 2 0.0 0.0 0 0? S 09:51 0:00 [kthreadd]
  root 3 0.0 0.0 0 0? S 09:51 0:00 [migration / 0]
  ... ...
  /> Ps -eo user, pid,% cpu,% mem, start, time, command | head -n 4
  USER PID% CPU% MEM STARTED TIME COMMAND
  root 1 0.0 0.1 09:51:08 00:00:02 / sbin / init
  root 2 0.0 0.0 09:51:08 00:00:00 [kthreadd]
  root 3 0.0 0.0 09:51:08 00:00:00 [migration / 0]
  The caveat here is that many processes and performance-related parameters exist ps, they are output table columns show the way out here just gives us a very commonly used several parameters, as more parameters, we We need to see the ps man page according to their actual application.
  Display # pid is 1 (init) to complete the process of data format
  /> Ps -fp 1
  UID PID PPID C STIME TTY TIME CMD
  root 1 0 0 05:16? 00:00:03 / sbin / init
  
  2. Change the process priority order (nice and renice):
  The most common way is to use the Shell command: nice [-n < priority>] [Instruction], which range from -20-19 priority, the highest of which -20, 19 minimum, only the system administrator can set negative level.
  # The background sleep 100 seconds while it is nice when you start value is set to 19
  /> Nice -n 19 sleep 100 &
  [1] 4661
  # The background sleep 100 seconds while it is nice when you start value is set to -19
  /> Nice -n -19 sleep 100 &
  [2] 4664
  # Ps -l output concerns two lines highlighted in yellow, their NI values and our execution is consistent with the value set.
  /> Ps -l
  F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
  4 S 0 2833 2829 0 80 0 - 1739 - pts / 2 00:00:00 bash
  0 S 0 4661 2833 0 99 19 - 1066 - pts / 2 00:00:00 sleep
  4 S 0 4664 2833 0 61 -19 - 1066 - pts / 2 00:00:00 sleep
  4 R 0 4665 2833 1 80 0 - 1231 - pts / 2 00:00:00 ps
  
  renice command is used for the process has been performed resetting nice value, the command includes the following common options:
Option Description
-g group name to use the program, modify all belong to the program group program priority.
-p priority levels to change the program, this parameter is the default value.
-u user name is specified, all belonging to modify the priority of the user program.

  # Switch to stephen-user to perform a background process, this process will sleep the sleep 1000 seconds in the background.
  /> Su stephen
  /> Sleep 1000 &
  [1] 4812
  /> Exit # back to the root user before switching
  # See background has started the process of sleep, the ni value is 0, the host user stephen
  /> Ps -eo user, pid, ni, command | grep stephen
  stephen 4812 0 sleep 1000
  root 4821 0 grep stephen
  # To specify the user a way to modify the nice value of all processes at the user
  /> Renice -n 5 -u stephen
  500: old priority 0, new priority 5
  # Ps again output from the execution results can be seen, nice value of the sleep daemon has been transferred into 5
  /> Ps -eo user, pid, ni, command | grep stephen
  stephen 4812 5 sleep 1000
  root 4826 0 grep stephen
  # Specified process pid nice way to modify the value of the process
  /> Renice -n 10 -p 4812
  4812: old priority 5, new priority 10
  # Run ps again, nice background value of the sleep process has become from May 10
  /> Ps -eo user, pid, ni, command | grep stephen
  stephen 4812 10 sleep 1000
  root 4829 0 grep stephen

 3. List the currently open file system tools (lsof):
  lsof (list opened files), an important feature of the system include file has been opened, if you do not specify any options or parameters, lsof lists all open files for all active processes. As we all know, linux environment, everything is a file, such as devices, directories, sockets and the like. Therefore, make good use of lsof command on linux daily management is very helpful. The following common options first give the command:
Option Description
-a list of the results of this option will be later option selected and operation.
-c command_prefix displayed in the process at the beginning of command_prefix open files.
-p PID Displays the PID open information file
+ D directory from folder directory to search (without regard subdirectories), list the file information in the directory open.
+ D directory from folder directory to search for (consider subdirectories), list the file information in the directory open.
-d num_of_fd to File Descriptor information matching 3-10 can be used to indicate the scope, 3,10 represent certain values.
-u user display a user has open files, which user can use regular expressions.
Protocol, port, and other network information Host -i monitor specified in the format: [proto] [@ host | addr] [: svc_list | port_list]

  # Check process opens / dev / null file.
  /> Lsof / dev / null | head -n 5
  COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
  init 1 root 0u CHR 1,3 0t0 3671 / dev / null
  init 1 root 1u CHR 1,3 0t0 3671 / dev / null
  init 1 root 2u CHR 1,3 0t0 3671 / dev / null
  udevd 397 root 0u CHR 1,3 0t0 3671 / dev / null

  # Check process open port 22
  /> Lsof -i: 22
  COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
  sshd 1582 root 3u IPv4 11989 0t0 TCP *: ssh (LISTEN)
  sshd 1582 root 4u IPv6 11991 0t0 TCP *: ssh (LISTEN)
  sshd 2829 root 3r IPv4 19635 0t0 TCP bogon: ssh-> bogon: 15264 (ESTABLISHED)

  # See the init process open files
  /> Lsof -c init
  COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
  init 1 root cwd DIR 8,2 4096 2 /
  init 1 root rtd DIR 8,2 4096 2 /
  init 1 root txt REG 8,2 136068 148567 / sbin / init
  init 1 root mem REG 8,2 58536 137507 /lib/libnss_files-2.12.so
  init 1 root mem REG 8,2 122232 186675 /lib/libgcc_s-4.4.4-20100726.so.1
  init 1 root mem REG 8,2 141492 186436 /lib/ld-2.12.so
  init 1 root mem REG 8,2 1855584 186631 /lib/libc-2.12.so
  init 1 root mem REG 8,2 133136 186632 /lib/libpthread-2.12.so
  init 1 root mem REG 8,2 99020 180422 /lib/libnih.so.1.0.0
  init 1 root mem REG 8,2 37304 186773 /lib/libnih-dbus.so.1.0.0
  init 1 root mem REG 8,2 41728 186633 /lib/librt-2.12.so
  init 1 root mem REG 8,2 286380 186634 /lib/libdbus-1.so.3.4.0
  init 1 root 0u CHR 1,3 0t0 3671 / dev / null
  init 1 root 1u CHR 1,3 0t0 3671 / dev / null
  init 1 root 2u CHR 1,3 0t0 3671 / dev / null
  init 1 root 3r FIFO 0,8 0t0 7969 pipe
  init 1 root 4w FIFO 0,8 0t0 7969 pipe
  init 1 root 5r DIR 0,10 0 1 inotify
  init 1 root 6r DIR 0,10 0 1 inotify
  init 1 root 7u unix 0xf61e3840 0t0 7970 socket
  init 1 root 9u unix 0xf3bab280 0t0 11211 socket
  In the FD column of the output above, the display is the File Descriptor number of the file, or the following contents:
  cwd: current working directory;
  mem: memory-mapped file;
  mmap: memory-mapped device;
  pd: parent directory;
  rtd: root directory;
  txt: program text (code and data);
  File Descriptor number of the file display modes are:
  r for read access;
  w for write access;
  u for read and write access;

  In the TYPE column of the output above, the display is the file type, such as:
  DIR: Directory
  LINK: link file
  REG: ordinary file


  # View pid for the process 1 (init) to open the file, which is equivalent to the output of the above command, they are init.
  /> Lsof -p 1
  # View owner to open the file as root processes.
  /> Lsof -u root
  # View owner is not root process open files.
  /> Lsof -u ^ root
  # View open protocol is tcp, ip is 192.168.220.134, port 22 for the process.
  /> Lsof -i tcp@192.168.220.134: 22
  COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
  sshd 2829 root 3r IPv4 19635 0t0 TCP bogon: ssh-> bogon: 15264 (ESTABLISHED)
  # View open / root folder, but does not consider the directory search
  /> Lsof + d / root
  # View open / root folder and its subdirectories Search
  /> Lsof + D / root
  # View open all processes FD (0-3) file
  /> Lsof -d 0-3
  # -a Option will result d + Select option and the -c option and carry out the operation, and outputs the combined results.
  /> Lsof + d.
  COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
  bash 9707 root cwd DIR 8,1 4096 39887.
  lsof 9791 root cwd DIR 8,1 4096 39887.
  lsof 9792 root cwd DIR 8,1 4096 39887.
  /> Lsof -a -c bash + d.
  COMMAND PID USER FD TYPE DEVICE SIZE / OFF NODE NAME
  bash 9707 root cwd DIR 8,1 4096 39887.
  Finally, the need for additional note is that if there are (delete) at the end of the file name, then the file has been deleted, but still remain in the cache.


  4. The process of find / kill command (pgrep / pkill):
  Find and kill the specified process, their options and parameters are identical, introduced here only pgrep. The following are commonly used command line options:
Option Description
-d Delimiter defined between multiple processes, if not defined, then the line breaks.
-n indicates if the program has multiple processes are running, only to find the latest and final start.
-o indicates if the program has multiple processes are running, only to find the oldest, that is the first to start.
-G Then follow a set group id, the command in the search, considering only the group list in the process.
-u Thereafter followed a set of valid user ID (effetive user id), the command in the search, considering only the effective user list in the process.
-U Thereafter followed a set of actual user ID (real user id), the command in the search, considering only the real user list in the process.
-x represents the process name must exactly match the above options can be part of the match.
-l will not only print pid, also the name of the printing process.
-f -l combined with the general, the parameters of the printing process.

  # Manually create two background processes
  /> Sleep 1000 &
  3456
  /> Sleep 1000 &
  3457

  # Find a process called sleep process, while the output of all find pid
  /> Pgrep sleep
  3456
  3457
  Process pid # Find a process called sleep, if there are multiple, among them the use of: separation, rather than separated by line breaks.
  /> Pgrep -d: sleep
  3456: 3457
  Process pid # Find a process called sleep, if there is more than one, here is the output of the last start that one.
  /> Pgrep -n sleep
  3457
  Process pid # Find a process called sleep, if there is more than one, here is the output of the first to start one.
  /> Pgrep -o sleep
  3456
  # Find a process called sleep, while the running processes of group root and stephen.
  /> Pgrep -G root, stephen sleep
  3456
  3457
  # Find a valid user ID is root and Oracle, a process called sleep process.
  /> Pgrep -u root, oracle sleep
  3456
  3457
  # Find the process actual user ID root and oracle, a process called sleep.
  /> Pgrep -U root, oracle sleep
  3456
  3457
  # Find a process called sleep process, pay attention to the process name found here must exactly match the parameter.
  /> Pgrep -x sleep
  3456
  3457
  # -x Does not support partial matches, sleep process will not be detected, so the following command to no avail.
  /> Pgrep -x sle
  # Find a process called sleep process, while the output of all find the pid and process name.
  /> Pgrep -l sleep
  3456 sleep
  3457 sleep
  # Find a process called sleep process, while the output of all find pid, name and process parameters at startup.
  /> Pgrep -lf sleep
  3456 sleep 1000
  3457 sleep 1000
  # Find a process called sleep process, while Comma Separated Values pid their output, in the results to the ps command, -f denotes a display full format, -p pid display list, ps will only list the output process within data.
  /> Pgrep -f sleep -d, | xargs ps -fp
  UID PID PPID C STIME TTY TIME CMD
  root 3456 2138 0 06:11 pts / 5 00:00:00 sleep 1000
  root 3457 2138 0 06:11 pts / 5 00:00:00 sleep 1000
     
         
         
         
  More:      
 
- PULL operation mechanism parsing XML Comments (Programming)
- Python context managers (Programming)
- Do not find ifconfig eth0 and IP address under CentOS6.5 (Linux)
- Zabbix monitoring Oracle Database use Orabbix plug (Enhanced Edition) (Database)
- How to view the Linux program or process used in the library (Linux)
- Getting Started with Linux: CentOS7 Install Mono with the yum command (Server)
- Linux partition command (Linux)
- CentOS 6.4 Python 2.6 upgrade to 2.7 (Linux)
- Linux data redirection (Linux)
- How to use jgit to manage Git submodule (Linux)
- Java objects to garbage collection (Programming)
- JavaScript, some conclusions about the implicit conversion (Programming)
- To modify the existing user ID and comments GPG key (Linux)
- Use PXE with kickstart to install Linux automatically (Linux)
- Linux (Debian) install software, missing dynamic link libraries .so (Linux)
- How Ubuntu Snappy Core 2 running on Raspberry Pi (Linux)
- Java rewrite the hashcode method (Programming)
- Help you make Git Bisect (Linux)
- Use OpenSSL to generate a certificate detailed process (Linux)
- Oracle GoldenGate Installation and Configuration Tutorial Introduction (Database)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.