バックアップファイルが書き込み中か確認するのにファイルサイズとタイムスタンプを見る以外の方法がないか調べたメモ
lsof
lsof
を使用することで他のどのプロセスが使用中かも含めて確認することができます。
ファイルを他のプロセスが使用しているか確認する
root@ubuntu-xenial:/tmp# touch test.txt
root@ubuntu-xenial:/tmp# less test.txt
(Ctrl+z で停止)
[1]+ 停止 less test.txt
root@ubuntu-xenial:/tmp# lsof test.txt
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
less 6090 root 4r REG 8,1 0 57574 test.txt
これで、実行コマンド、pid、実行ユーザーなどを確認できます。
注意点として、一般ユーザーからでは全ての他のプロセスは見えませんでした。
(rootがアクセス中のファイルに一般ユーザーが lsof
で確認しても使用中か見えない)
inotify-tools
もう少し詳細に見たい場合は、inotify-tools
を使用すると良さそうです。
すでに詳しい記事があったため、以下などを参照して下さい。
inotify-toolsでファイルやディレクトリを監視する - Qiita
参考
lsofの使い方 - プロセスが使用中のファイルを調べる - うまいぼうぶろぐ
lsofコマンドで覚えておきたい使い方9個 | 俺的備忘録 〜なんかいろいろ〜