Unix/Linux命令行小技巧(2)- Linux上kill占用某端口的进程

Linux平台上kill占用某端口进程命令:

fuser -k port/tcp(udp)

举个例子:

[root@localhost redis-2.8.19]# ps -ef | grep redis
root     10049 35207  0 17:33 pts/7    00:00:00 ./src/redis-server *:6379
root     10116 35207  0 17:33 pts/7    00:00:00 grep redis             
[root@localhost redis-2.8.19]# fuser -k 6379/tcp
6379/tcp:            10049
[1]+  Killed                  ./src/redis-server

可以看到,占用6379端口的进程被杀死了。
技巧出处:https://twitter.com/nixcraft/status/162914646125330432

Unix/Linux命令行小技巧(1)- 显示运行进程的PID

Bash中定义如下函数(函数参数为程序名):

findpid() { ps axc|awk "{if (\$5==\"$1\") print \$1}"; }

执行效果:

[root@localhost ~]# findpid() { ps axc|awk "{if (\$5==\"$1\") print \$1}"; }
[root@localhost ~]# findpid tail
16049
25206
40701
48132

技巧出处:https://twitter.com/nixcraft/status/158835574508240896