Giter VIP home page Giter VIP logo

Comments (5)

capn-damo avatar capn-damo commented on June 22, 2024

By all means. You know this stuff better than me! (And add your name to the header info, since you have contributed a lot to the script ;) )

from bunsen-utilities.

 avatar commented on June 22, 2024

@johnraff Why is SIGKILL necessary? Does the program ignore SIGTERM? If need be, send SIGTERM, wait, check again and then send SIGKILL.

from bunsen-utilities.

johnraff avatar johnraff commented on June 22, 2024

SIGKILL should not be necessary, but the tint2 version in Jessie seems to have a freezing bug, and when it occurs SIGKILL is the only signal that will kill it.
http://crunchbang.org/forums/viewtopic.php?pid=430787#p430787
Yes the script could be enhanced to try SIGTERM first. It's a bit of extra code, but I'll try it today.

In fact, the script could fairly easily be expanded to take any process name as argument to make it a generic bl-restart for possible use elsewhere. It would mean either modifying the call in bl-tint2-pipemenu or making a wrapper script bl-tint2-restart which called bl-restart tint2.

from bunsen-utilities.

johnraff avatar johnraff commented on June 22, 2024

@2ion I guess a 0.5s wait before using SIGKILL should be enough?
something like:

declare -A commands # associative array
while read pid cmd; do
    if [[ ${cmd%% *} = tint2 ]]; then
        kill "$pid"
        sleep 0.5
        kill -0 "$pid" && kill -KILL "$pid"
        commands[$cmd]=1 # duplicate commands will be launched only once
    fi
done <<< "$(pgrep -a tint2)"

Although really I'm not sure if there's any meaning in testing with kill -0 in kill -0 "$pid" && kill -KILL "$pid".
Just kill -KILL "$pid" >/dev/null 2>&1 after the sleep would be enough, no?

from bunsen-utilities.

johnraff avatar johnraff commented on June 22, 2024

I've thought some more, and there's a possible race condition with the above code. During the sleep 0.5 it's possible, even if unlikely, that another process would start with the same $pid that the killed tint2 process had. That innocent process would then be killed.

It can be avoided by re-running the loop using the output of pgrep -a tint2. Thus:

#!/bin/bash
#
# bl-tint2restart to be used by bl-tint2-pipemenu
# Written for BunsenLabs Linux by <damo> June 2015
# and <johnraff> July 2015

declare -A commands # associative array

while read pid cmd; do
    if [[ ${cmd%% *} = tint2 ]]; then
        kill "$pid"
        commands[$cmd]=1 # duplicate commands will be launched only once
    fi
done <<< "$(pgrep -a tint2)"

sleep 1

# any processes still running will be killed with SIGKILL
while read pid cmd; do
    if [[ ${cmd%% *} = tint2 ]]; then
        kill -KILL "$pid"
        commands[$cmd]=1
    fi
done <<< "$(pgrep -a tint2)"

sleep 1
for i in "${!commands[@]}" # go through the indexes
do
    (setsid $i &)
    sleep 0.1
done

sleep 1
bl-compositor --restart  # restart compositor

exit 0

from bunsen-utilities.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.