Instructionals/Technical From HowTo Geek
-
HowTo Geek ☛ Avoid These Problems By Limiting Bash Scripts to Run Once At A Time
Some scripts shouldn’t be launched if a previous instance of that script is still running. If your script consumes excessive CPU time and RAM, or generates a lot of network bandwidth or disk thrashing, limiting its execution to one instance at a time is common sense.
But it’s not just resource hogs that need to run in isolation. If your script modifies files, there can be a conflict between two (or more) instances of the script as they fight over access to the files. Updates might be lost, or the file might be corrupted.
One technique to avoid these problem scenarios is to have the script check that there are no other versions of itself running. If it detects any other running copies, the script self-terminates.
Another technique is to engineer the script in such a way that it locks itself down when it is launched, preventing any other copies from running.
We’re going to look at two examples of the first technique, and then we’ll look at one way to do the second.
-
HowTo Geek ☛ How (and Why) to Prevent a Bash Script From Relaunching Too Soon
Depending on what it’s doing and which other processes it may launch, a Bash script can consume as much RAM and CPU time as any other resource-hungry process. It can be useful to limit how frequently such a script can be launched.
Enforcing a period of respite between each run of a heavyweight script stops it from hogging resources. Computationally expensive scripts can monopolize computers to the point where other users experience a drop in performance. In extreme cases, if the script causes a lot of disk churn, for example, it can even hasten the demise of your hardware.
Of course, engineering a scheme that limits how soon you can relaunch a script adds code to your script, and gives it one more thing to do. That might sound counterproductive, but if the checks are lightweight and fast, their tiny overheads are far outweighed by their resource savings.
-
HowTo Geek ☛ Always Know Which Git Branch You're In With This Linux Trick
Using branches in Git is so painless, we do it a lot. So much that keeping track of your current branch isn’t easy. With this trick, you’ll never forget your current branch.
-
HowTo Geek ☛ The Hidden Files in Your Linux Home Directory, Explained
Hidden files are a useful built-in feature of Linux that helps to keep your system organized. But older or poorly behaved apps can clutter your home directory with many unnecessary files. Find out how to deal with the mess.