特にhttps://unix.stackexchange.com/questions/24952/script-to-monitor-folder-for-new-filesのスクリプトを使用して、inotifywait の使用方法を学習しています。理解できないのは、 を使用すると、スクリプトが常に 2 回表示される理由pid x
です。
36285 pts/1 S+ 0:00 /bin/bash ./observe2.sh /home/user1/testfolder
36286 pts/1 S+ 0:00 inotifywait -m /home/user1/testfolder -e create -e moved_to
36287 pts/1 S+ 0:00 /bin/bash ./observe2.sh /home/user1/testfolder
テストを迅速に行うために、リンクされたスクリプトを変更して、 $1 経由で任意のフォルダーを渡して監視し、次のように保存できるようにしましたobserve2.sh
。
#!/bin/bash
inotifywait -m $1 -e create -e moved_to |
while read path action file; do
echo "The file '$file' appeared in directory '$path' via '$action'"
# do something with the file
done
スクリプト プロセスが 2 回表示されるのはなぜですか? プロセスのどこかにフォークはありますか?2つのプロセスのこの動作が正確に発生している理由を誰かが説明できますか?