我正在学习使用 inotifywait,特别是使用以下脚本:https ://unix.stackexchange.com/questions/24952/script-to-monitor-folder-for-new-files 。我不明白的是为什么我的脚本在我使用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
为什么脚本进程会出现两次?在这个过程中的某个地方有叉子吗?有人可以解释为什么两个进程的这种行为正在发生吗?