0%

Linux 之 skill 命令

Linux 之 skill 命令

..note::
江山代有才人出,各领风骚数百年。
赵翼《论诗五首·其二》

Linux skill命令送个讯号给正在执行的程序,预设的讯息为 TERM (中断),较常使用的讯息为 HUPINTKILLSTOPCONT 和 0。

讯息有三种写法:分别为 -9、-SIGKILL、-KILL,可以使用 -l 或 -L 已列出可使用的讯息。

官方含义为:

skill, snice - send a signal or report process status

语法

1
2
$ skill [signal] [options] expression
$ snice [new priority] [options] expression

一般参数:

  • -i, --interactive :交互模式,每个动作将要被确认
  • -l, --list : 列出所有的信号
  • -L, --table : 列出所有的信号名

列出所有的信号

1
2
3
$ skill -l
HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT
CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS

用漂亮的表格列出所有的信号

1
2
3
4
5
6
$ skill -L
1 HUP 2 INT 3 QUIT 4 ILL 5 TRAP 6 ABRT 7 BUS
8 FPE 9 KILL 10 USR1 11 SEGV 12 USR2 13 PIPE 14 ALRM
15 TERM 16 STKFLT 17 CHLD 18 CONT 19 STOP 20 TSTP 21 TTIN
22 TTOU 23 URG 24 XCPU 25 XFSZ 26 VTALRM 27 PROF 28 WINCH
29 POLL 30 PWR 31 SYS

kill掉用户users在PTY的进程

1
$ skill -KILL -t /dev/pts/*

停止三个使用者 user1、user2、user3

1
$ skill -STOP -u user1 -u user2 -u  user3

相关命令

  • :ref:kill<linux-beginner-kill>
  • :ref:killall<linux-beginner-killall>
  • :ref:nice<linux-beginner-nice>
  • :ref:pkill<linux-beginner-pkill>
  • :ref:renice<linux-beginner-renice>
  • :ref:signal<linux-beginner-signal>

OPTIONS

PROCESS SELECTION OPTIONS
Selection criteria can be: terminal, user, pid, command. The options below may be used to ensure correct interpretation.

   -t, --tty tty
          The next expression is a terminal (tty or pty).

   -u, --user user
          The next expression is a username.

   -p, --pid pid
          The next expression is a process ID number.

   -c, --command command
          The next expression is a command name.

   --ns pid
          Match the processes that belong to the same namespace as pid.

   --nslist ns,...
          list which namespaces will be considered for the --ns option.  Available namespaces: ipc,  mnt,  net,  pid,  user,
          uts.

SIGNALS
The behavior of signals is explained in signal(7) manual page.

EXAMPLES
snice -c seti -c crack +7
Slow down seti and crack commands.

处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道