0

This is a cross-post from RPi. I wrote a series of bash functions to allow me to switch between Raspbian, kodi, and emulationstation so that I could use Siri/homebridge to initiate the switch. Switching works all pretty well. The only problem is that stopping any of the OSs without starting another one leaves the console’s connection to VT1 in some sort of weird state. All I see is a black screen.

I can manually fix this using either alt+F1 or by executing sudo chvt 2;sudo chvt 1 to reinitialize VT1, but I would prefer to avoid this bad state entirely. I assume that this is happening as a side-effect using pkill to stop the OSs. E.g. pkill emulationstatio;pkill xinit;pkill kodi;.

I could add sudo chvt 2;sudo chvt 1 to my stop functions, but I’d rather not since I don’t know in that function whether another OS is starting or going to start.

So how can I cleanly stop kodi/emulationstation/raspbian so that VT 1 is left in a good state so that I can see the console after the OS has stopped?

BTW, this is on a raspberry pi. I have been testing via ssh and watching the results on the hdmi-connected TV from the couch.

0

A child process of kodi still has control of vt 1. Just doing pkill kodi orphans the child, but doesn't kill it. The screen goes black because kodi is effectively half-dead. Killing kodi and all its child processes will return you back to the console.

To get all the pids of kodi and its children, you can do something like this (in bash). First, create a function to get all child PIDs of a given PID:

getfamilypids() {
    local inpid="$1"
    local pidarray=()

    function getfamilypidshelper() {
        local pidin="$1"
        pidarray+=($pidin)
        local CPIDS="$(pgrep -P $pidin)"
        for cpid in $CPIDS; do
            getfamilypidshelper $cpid
        done
    }

    getfamilypidshelper "$inpid"

    #reverse the array
    local rpidarray=()
    for ((z=${#pidarray[*]}-1; z>-1; z--)); do
        rpidarray+=(${pidarray[z]})
    done

    echo ${rpidarray[*]}
}

To get the PID of the kodi process you started, you can do this:

pgrep -f kodi

Then you can get the child processes of the PID you get back:

getfamilypids __PID_FROM_ABOVE__

Note, the order of the PIDs from getfamilypids is reversed. You should kill them sequentially from left to right. I wrote a method to automatically kill all of them and wait for them to finish cleanly before killing the next, but that's a topic for another question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.