byte order and Lsof

Source: Internet
Author: User
Tags socket port number
byte order Concept the key points to be explained in the concept: The concept of small and big endian in the host byte-order. Big and small ends are concepts that are stored on the host with a multibyte integer. network byte order, when a multibyte integer is transmitted over a network, is specified to be transmitted in big endian order. In a host of different types of CPUs, memory stores multibyte integer sequences in two ways, called host byte order (Hbo-host byte order): Small End sequence(Little-endian)-low-order bytes are stored at low addresses, and low bytes are stored at the start address, known as the "Little-endian" byte order, which is used by Intel, AMD, and so on; Big- endian sequence(Big-endian)-The high-order byte is stored at a low address, storing high bytes in the start address, called "Big-endian" byte order, adopted by arm, Motorola, etc. because of the CPU design and the implementation of the OS (the same CPU, OS, HBO will different), there will be different byte-order types on different systems. These byte orders refer to integers larger than one byte (16-bit, 32-bit ... In memory, this is called the host order. P48 's example is not very intuitive, use this example below to illustrate the example: in-memory double-word 0x01020304 (DWORD) storage mode
Memory address 0x00000001 0x00000002 0x00000003 0x00000004
LE 0x04 0x03 0x02 0x01
Be 0x01 0x02 0x03 0x04
Can talk about the origin of the head of the big heads: "Endian" from the Jonathan Swift novel "Gulliver's Travels." In the novel, the small country for boiled eggs from the big one end (big-end) peel off or a little side (Little-end) Peel and controversy, the dispute between the two sides are called "large-endian" and "small end faction." The data transmitted in the network must be nbo-network byte order according to the net byte order, that is, the big endian byte order on most PC, when the application process will send the integer into the socket, it needs to convert to the network byte order; When the application process takes an integer from the socket, it is converted to a small-endian byte order. The tutorial is not a strict statement, it should be said: For a multi-byte integer, the host will its Write into Socket before you convert it to a network byte order, and from the Socket after the read out to convert to host byte order, and then processing. Send from local (send, write) An integer value to the network, need to Hbo->nbo from the network (recv, read) An integer value to the local, need to NBO->HBO Simple Web Tools lsof Lsof Introduction lsof (list open files) is a tool that lists open files for the current system. In a Linux environment, everything is in the form of files, with files that not only access regular data, but also access to network connectivity and hardware. So, such as Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) sockets, the system assigns a file descriptor to the application in the background, regardless of the nature of the file, which provides a common interface for the interaction between the application and the underlying operating system. Because the application opens a descriptor list of files that provides a lot of information about the application itself, it is helpful to see the list through the Lsof tool for system monitoring and troubleshooting. lsof use   lsof output information meaning enter lsof under the terminal to display the file that the system opens, because lsof needs to access core memory and various files, so it must run as root to fully function. command    pid      USER   fd      TYPE      device     size       node       NAME init       1          root  cwd      dir       3,3        1024       2        / init       1         root  rtd      dir       3,3        1024       2         /init       1         root  txt      REG       3,3        38432      1763452 /sbin/init init       1         root  mem      REG        3,3       106114     1091620 /lib /libdl-2.6.so init       1         Root   mem      reg       3,3       7560696    1091614 /lib/libc-2.6.so init       1          root  mem      reg        3,3       79460      1091669  /lib/libselinux.so.1 init       1          root  mem      reg       3,3        223280     1091668 /lib/libsepol.so.1 init        1         root  mem      REG        3,3       564136     1091607 /lib/ld-2.6.so init       1        &nBsp root  10u      fifo      0,15                   1309    /dev /initctl each row displays an open file, and if you do not specify the criteria, all files opened by all processes are displayed by default. Lsof the meaning of the output column information is as follows: COMMAND: Name of the process PID: Process identifier USER: Process owner FD: File descriptor, the application recognizes the file through a file descriptor. such as CWD, TXT, etc. type: file type, such as Dir, Reg and other DEVICE: Specify the name of the disk size: size of File Node: Index node (identity of file on disk) name: Open the exact name of the file where the file descriptor in the FD column is CWD The value represents the current working directory of the application, which is the directory that the application launches, unless it makes changes to the directory itself. TXT types of files are program code, such as the application binaries themselves or shared libraries, as shown in the list above in the/sbin/init program. The second value represents the application's file descriptor, which is an integer returned when the file is opened. As on the last line of file/dev/initctl, its file descriptor is 10. U indicates that the file is open and is in read/write mode instead of read-only ® or write-only (w) mode. Also, a capital W indicates that the application has a write lock on the entire file. This file descriptor is used to ensure that only one instance of the application can be opened at a time. When each application is initially opened, it has three file descriptors, from 0 to 2, representing standard input, output, and error streams, respectively. So most applications open files with FD starting from 3. The Type column is more intuitive than the FD column. Files and directories are called REG and Dir, respectively. The CHR and BLK, respectively, represent characters and block devices, or UNIX, FIFO, and IPV4, respectively, representing the UNIX domain sockets, first in and Out (FIFO) queues, and Internet Protocol (IP) sockets. Common usage of lsof common parameters lsof is to find the name and number of files opened by the application. Can be used to find out where a particular application logs the log data, or to track an issue. CasesFor example, Linux restricts the number of files that a process can open. This is usually a large number, so there is no problem, and when needed, the application can request a larger value (up to a certain limit). If you suspect that the application is running out of file descriptors, you can use Lsof to count the number of open files for verification. The lsof syntax format is: lsof [options] filename common parameter list: lsof  filename Displays all processes that open the specified file lsof-a indicates that two parameters must be met before the results are displayed lsof-c String&nbs p;  Displays the command column that contains the specified characters for all open files Lsof-u username  displays the files that belong to the user process open Lsof-g GID shows the process of attribution to GID lsof +d/dir/display directory is entered Cheng opened the file lsof +d/dir/, but will search all directories under the directory, the time is relatively long lsof-d FD display specifies the file descriptor of the process lsof-n do not convert IP to hostname, the default is not to add the-n parameter lsof-i to display the eligible LSOF-I[46] [protocol][@hostname |hostaddr][:service|port]             --IPV4 or IPV6             protocol --TCP or UDP             hostname---Internet host name             hostaddr-IPV4 address              Service- Service name in/etc/service (can be more than one)             Port-- Port number (can be more than one) for example: see 22 port now running condition # lsof-i: command  PID user   fd   TYPE DEVICE SIZE NODE NAME sshd    1409 root    3u  ipv6   5678        TCP *:ssh (LISTEN) View files with file type txt opened by the root user process: # lsof-a-u root-d txt command    PID user  F d      TYPE device    size    NODE NAME init        1    root txt       reg    3,3    38432 1763452/sbin/init mingetty  1632 root txt       REG     3,3   14366 1763337/sbin/mingetty mingetty  1633 root txt       reg    3,3   14366 1763337/sbin/mingettymingetty  1634 Root txt       reg    3,3   14366 1763337/ Sbin/mingetty mingetty  1635 root txt       reg    3,3   14366 1763337/sbin/mingetty mingetty  1636 root txt       REG    3,3   14366 1763337/sbin/mingetty mingetty  1637 root txt       REG     3,3   14366 1763337/sbin/mingetty kdm        1638 Root txt       reg    3,3  132548 1428194/USR/BIN/KDM X           1670 Root txt       reg     3,3 1716396 1428336/usr/bin/xorg kdm        1671 Root txt        reg    3,3  132548 1428194/USR/BIN/KDM startkde  2427 root txt       reg    3,3  645408 1544195/bin/ Bash ... ... 

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.