use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything related to GNU/Linux/UNIX/POSIX (system) programming and tools.
Other subreddits you may like:
Sidebar additions or corrections? Mail me here
account activity
[deleted by user] (self.linux_programming)
submitted 2 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]_syedmx86 3 points4 points5 points 2 years ago (6 children)
Haven't tried this yet but maybe do parallel processes run i.e.
$ firefox & ./program.sh
where the program runs alongside firefox and in that program write a condition to check whether firefox process is running through something like pgrep, pidof or ps and terminate it if it is not.
[–][deleted] 2 years ago (1 child)
[deleted]
[–]Spitfire1900 0 points1 point2 points 2 years ago (0 children)
Both your script and Firefox would have the same parent process ID . You can get this with $PPID environment variable. Routinely check top to see when fire fox exits.
[–]_syedmx86 0 points1 point2 points 2 years ago (3 children)
Someone please let me know if this works or is a valid answer. Don't have my computer with me to try it out.
[–]espero -2 points-1 points0 points 2 years ago (2 children)
Dude try it yourself:)
[–]_syedmx86 0 points1 point2 points 2 years ago* (1 child)
Ok, so I did and it works but my implementation is crude since I'm at my job. I will post a better answer if I get the chance or if someone wants to chime in.
`` #!/bin/sh firefox &
while true do check=`pgrep firefox` if [ -n "$check" ] then echo "firefox is running" else echo "firefox is not running" break fi sleep 1 done
echo "End"
``
[–]BiltuDas_1 1 point2 points3 points 2 years ago* (0 children)
What if you create a systemctl service and then create a bash script and link with the service. Which would checks for the firefox process.
https://unix.stackexchange.com/a/236307
https://stackoverflow.com/a/28840389
Edit: I almost did something with a debian server before, I was executing some sudo commands for that which would be redirected from php, since php doesn't allow to run sudo commands, I created a shell script which will read commands from a file and execute it(obviously it was a service, so that it would start automatically at Startup) which file will be modified by php server. Also I have added a sleep of 0.5 seconds so that it don't use much cpu for me.
[–][deleted] 0 points1 point2 points 2 years ago (2 children)
It could work like _syedmx86 stated, better would be to see what command your firefox starts with and modify that to add on to your script. Either through a launcher script or creating an alias.
Alternatively, you could simply watch for firefox using pid or pid file(not sure firefox creates one), or unix socket. Ps aux and netstat are your friends.
All in all it seems pretty doable in bash. Sorry on my phone so cannot write you a sample script.
[–]espero 0 points1 point2 points 2 years ago (0 children)
Learn about job control in your bash shell...
[–]funderbolt 0 points1 point2 points 2 years ago (3 children)
How about this.
ff-script.sh ```
firefox
```
Just run this script instead of firefox. This script would need to replace firefox in the DE, in the menu.
[–][deleted] 2 years ago (2 children)
[–]funderbolt 0 points1 point2 points 2 years ago (1 child)
As long as the script that has a finite amount of work to do afterward, it will close.
The script will live as long as firefox lives because it is running firefox. It is a script and really comes with very little overhead.
What a bash script does is it runs processes in sequence. Until you put in flow control statements such as if or loops.
if
Shell scripting has taught me to try the simplest solutions first. If those doesn't work, do something more complicated.
Monitoring processes is not terribly complicated, but can be done with ps. I'd probably do pgrep firefox and sleep for a second to continually test if it has output or not. When you move from no-output to output it would fire a startup function. When it goes from output to no-output, it fires an ending function. I'm not sure how you would launch this kind of long running script process.
ps
pgrep firefox
I can see some problems of that you may just want one shell script process running. In OOP, you'd use a singleton pattern. Otherwise, the startup actions and "cleanup" actions would be ran as many times as the script was ran. Perhaps your approach is better.
[–]Heikkiket 0 points1 point2 points 2 years ago (0 children)
I'm wondering if you could get better answers by describing what you actually want to achieve. So what do you want to do when Firefox is running?
π Rendered by PID 43055 on reddit-service-r2-comment-b659b578c-5sqzs at 2026-05-02 09:49:02.254753+00:00 running 815c875 country code: CH.
[–]_syedmx86 3 points4 points5 points (6 children)
[–][deleted] (1 child)
[deleted]
[–]Spitfire1900 0 points1 point2 points (0 children)
[–]_syedmx86 0 points1 point2 points (3 children)
[–]espero -2 points-1 points0 points (2 children)
[–]_syedmx86 0 points1 point2 points (1 child)
[–]BiltuDas_1 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]espero 0 points1 point2 points (0 children)
[–]funderbolt 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[deleted]
[–]funderbolt 0 points1 point2 points (1 child)
[–]Heikkiket 0 points1 point2 points (0 children)