常用的linux指令

1. ps 查看进程情况

ps -ef 显示所有进程信息,连同命令行

ps -ef | grep python 查找进程名为python的进程

  • UID :程序被该 UID 所拥有
  • PID :就是这个程序的 ID
  • PPID :则是其上级父程序的ID
  • C :CPU使用的资源百分比
  • STIME :系统启动时间
  • TTY :登入者的终端机位置
  • TIME :使用掉的CPU时间。
  • CMD :所下达的是什么指令
UID        PID       PPID      C     STIME       TTY            TIME        CMD
root       929          1      0     08:55         ?        00:00:03        /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
doubles+ 13218       7780      0     14:09    pts/20        00:00:00        grep --color=auto python

2. kill 杀掉进程

kill -9 yourpid

kill 与 kill -9的区别

3. lsof查看某个端口(port)是否被占用

lsof -i
lsof -i:80 # 查看80端口被占用的情况

lsof输出各列信息

  • COMMAND:进程的名称
  • PID:进程标识符
  • PPID:父进程标识符(需要指定-R参数)
  • USER:进程所有者
  • PGID:进程所属组
  • FD:文件描述符,应用程序通过文件描述符识别该文件。如cwd、txt等

    • cwd:表示current work dirctory,即:应用程序的当前工作目录,这是该应用程序启动的目录,除非它本身对这个目录进行更改
    • txt :该类型的文件是程序代码,如应用程序二进制文件本身或共享库,如上列表中显示的 /sbin/init 程序
    • lnn:library references (AIX);
    • er:FD information error (see NAME column);
    • jld:jail directory (FreeBSD);
    • ltx:shared library text (code and data);
    • mxx :hex memory-mapped type number xx.
    • m86:DOS Merge mapped file;
    • mem:memory-mapped file;
    • mmap:memory-mapped device;
    • pd:parent directory;
    • rtd:root directory;
    • tr:kernel trace file (OpenBSD);
    • v86 VP/ix mapped file;
    • 0:表示标准输出
    • 1:表示标准输入
    • 2:表示标准错误

    一般在标准输出、标准错误、标准输入后还跟着文件状态模式:r、w、u等

    • u:表示该文件被打开并处于读取/写入模式
    • r:表示该文件被打开并处于只读模式
    • w:表示该文件被打开并处于
    • 空格:表示该文件的状态模式为unknow,且没有锁定
    • -:表示该文件的状态模式为unknow,且被锁定

    同时在文件状态模式后面,还跟着相关的锁

    • N:for a Solaris NFS lock of unknown type;
    • r:for read lock on part of the file;
    • R:for a read lock on the entire file;
    • w:for a write lock on part of the file;(文件的部分写锁)
    • W:for a write lock on the entire file;(整个文件的写锁)
    • u:for a read and write lock of any length;
    • U:for a lock of unknown type;
    • x:for an SCO OpenServer Xenix lock on part of the file;
    • X:for an SCO OpenServer Xenix lock on the entire file;
    • space:if there is no lock.
  • TYPE:文件类型,如DIR、REG等,常见的文件类型
    • DIR:表示目录
    • CHR:表示字符类型
    • BLK:块设备类型
    • UNIX: UNIX 域套接字
    • FIFO:先进先出 (FIFO) 队列
    • IPv4:网际协议 (IP) 套接字
  • DEVICE:指定磁盘的名称
  • SIZE:文件的大小
  • NODE:索引节点(文件在磁盘上的标识)
  • NAME:打开文件的确切名称

猜你喜欢

转载自blog.csdn.net/jason_cuijiahui/article/details/80225115