My question involves two programs (kodi and xscreensaver).  Since I have encountered this with other applications, let me be more general and say I have two applications, say App1 and App2.  I wish for App2 to run continuously from startup to shutdown, but often I use App1 while I'm at the computer.  I even sometimes forget to close App1 if I step away.  I wish for App2 to run with it's default setup if App1 is not running. If App1 is running, then I wish for App2 to change it's behavior, but if App1 has been running for a long time (say an hour and a half) then App2 should resume with it's normal setup.I figured that I could accomplish this with a bash script and something else like perhaps cron or start-stop-daemon.  Here is what I've done so far in bash, in a file named Action_Needed.sh:    #!/bin/bash    # Determine if App1 and App2 are running at the same time    # Exit with 0 if yes, Exit with 1 if not    ps -e | grep -q App1    if [ $? -eq 0 ]    then        # App2 should always be running, but check        # anyway.  This could potentially be used        # to restart App2 automatically, if for some        # reason it was closed or crashed.        ps -e | grep -q App2        if [ $? -eq 0 ]        then            return 0        else            return 1    fi    else        return 1    fiIt's simple enough to use this script together with Cron to execute every minute or so and change the behavior of App2 whenever the above script exits with status 0.What should I do in the situation where App1 is running, and has been for a long time (say an hour and half) and I wish for App2 to continue to run as normal?  Should I use something other than Cron?
How to control multiple processes based on user defined conditions continuously
process;cron;ipc
So, I gather you want to check a process with a given name, and do some choice based on if it's running or not, and how long it has been running?To find the process ID of the process, you could grep the output of ps, or use pidof as in the example linked in the comments, or similarly, use pgrep. Whichever your system has. (e.g. pgrep is in the procps package on Debian.)The other thing you wanted, is the time the target program has been running. On recent-ish Linux systems, you can use ps --no-headers -oetimes $PID to get the time in seconds since the process was started. So, something like this:#/bin/shtarget=App1   # target=$1  # uncoment to take the target from the command linepid=$(pgrep --oldest $target)  if [ -n $pid ] ; then    time=$(ps --no-headers -oetimes $pid)    echo Oldest $target has been running for $time seconds    if [ $time -gt 5400 ] ; then        echo That's more than 1.5 hours    fifi Though note that pgrep (and pidof) will happily return more than one PID if the search matches more than one process. You'll have to deal with that somehow, either by making the match narrow enough (pgrep -f can be useful here), picking the --newest or --oldest with pgrep, or modifying the script to only take one of the PID's output by the program.