
Kill open file
Let's say user john.doe is using the less command to read the file /home/john.doe/example.file.
[root@server1 `]# fuser -v /home/john.doe
USER PID ACCESS COMMAND
/home/john.doe: john.doe 5010 ..c.. less
The -k or --kill option can be used to kill the process.
[root@server1 `]# fuser -k /home/john.doe/example.file
/home/john.doe/example.file: 5010
In john.doe terminal, message "killed" will be displayed.
example.file (END)killed
[john.doe@server1 ~]#
By default, the -k or --kill option will use the kill signal, SIGKILL. The -l or --list-signals option can be used to list the available signals.
[root@server1 `]# fuser -l
HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
STKFLT CHLD CONT STOP ISTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS
UNUSED
The -SIGNAL option can be used to use the preferred kill signal (replace SIGNAL with the prefer signal). In this example, the hang up (HUP) signal is used.
[root@server1 `]# fuser -k -HUP /home/john.doe/example.file
/home/john.doe/example.file: 5046
In john.doe terminal, message "hangup" will be displayed.
example.file (END)hangup
[john.doe@server1 ~]#
To proceed with caution, the -i or --interactive option can be used to display a prompt before issuing a kill signal.
[root@server1 `]# fuser -k -i /home/john.doe/example.file
Kill process 5099? (y/N)
Kill network connection
Let's say john.doe has made an SSH connection to the server.
[root@server1 `]# fuser -v -n tcp 22
USER PID ACCESS COMMAND
22/tcp: john.doe 8815 F.... sshd
The -k or --kill and -n or --namespace option can be used to kill a network connection.
[root@server1 `]# fuser -k -n tcp /home/john.doe/sshd
In john.doe shell, a message such as Server unexpectedly closed network connection will be displayed, and john.doe will lose SSH connection to the server.
Did you find this article helpful?
If so, consider buying me a coffee over at