From edb37abc9eda004a960e3e792b5b4be3d403a7e9 Mon Sep 17 00:00:00 2001 From: Xiao Pan Date: Sun, 5 May 2024 20:19:04 -0700 Subject: dyafk killall firefox pid cause ungracefully poweroff and prompt warning cause not actually open url, kill only parent process maybe can fix --- sh/dyafk | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'sh/dyafk') diff --git a/sh/dyafk b/sh/dyafk index 005b39f..e982e03 100755 --- a/sh/dyafk +++ b/sh/dyafk @@ -8,11 +8,17 @@ while :; do if [ "$(curl -s https://www.douyu.com/betard/9640128 | jq '.room.show_status')" -eq 1 ]; then if ! pidof -q firefox; then firefox --headless --profile "$HOME/.mozilla/firefox/dyafk" https://www.douyu.com/9640128 & + # assign previous background process to pid variable + pid=$! fi else - if pidof -q firefox; then - kill $(pidof firefox) 2>/dev/null - # for logging, so I know when firefox killed, which also need that `if pidof -q firefox` + if [ "$pid" ]; then + # seems need to only SIGTERM kill the parent firefox process, else firefox will prompt me firefox closed unexpectedly warning which cause firefox not actually open the url + # https://www.reddit.com/r/firefox/comments/fq1mhi/kill_firefox_gracefully_via_terminal_headless/ + # firefox seems now can handle SIGTERM on linux? https://bugzilla.mozilla.org/show_bug.cgi?id=1837907 + kill "$pid" + pid= + # for logging, I want to know when firefox killed echo 'kill firefox' fi fi -- cgit v1.2.3-70-g09d2