這是你似乎用什麼來形容,但可能不是你真正需要的東西。這是一種破解....
#!/usr/bin/bash
trap 'exit 0' SIGUSR1 # this is the normal successful exit point
# trigger the trap if ftp in a background process completes before 10 seconds
(ftp -inv $FTPDEST <<-EOF 2>>logfile
user $USER $PASS
put $file
EOF
kill -s SIGUSR1 $PPID) & # last line here shuts process down. and exits with success
childpid=$! # get the pid of the child running in background
sleep 10 # let it run 10 seconds
kill $childpid # kill off the ftp command, hope we get killed of first
wait
exit 1 # error exit ftp got hung up
家長等待10秒,而ftp子成功完成後不到10秒成功退出。
成功意味着孩子向父母發送SIGUSR1信號,然後通過陷阱退出。
如果孩子需要的時間太長,父母會殺死較慢的ftp孩子並退出並出錯。
如果你想殺死每個ftp進程,像'pkill ftp'應該足夠了。但這只是一個假設,或者你想殺死腳本啓動的獨特ftp進程? – jbh
我只想殺死ftp進程腳本啓動,如果在腳本結束時它還沒有退出。 – user2653557