a bit of awk — unix classics

I have a need to stop a process (or kill it) that is in the background. I can do this the old fashioned way by performing a ps aux | grep <process-name> to look for that specific process name’s process id, then perform a kill --signal SIGINT <process-id> to have it cleanly shut down. The process has a handler for SIGINT so that it can cleanly release resources and exit properly. But that manual process gets to be annoying if for no other reason that I’m lazy and tend to, well, forget some bits from time to time. That’s why automation is a good thing to do, as much as reasonably possible. I have it “written down” correctly so that I can just execute the function in which all of this is defined and implemented.

For this example I have a Python script, silly_clock.py, started every time I log into the pi account on my Raspberry Pi 5. It’s one of the examples in luma.led_matrix. It drives a four digit 8×8 LED matrix display, showing the time and then every minute scrolling the date across the display. I like it, but it’s important because it shows that the Raspberry Pi 5’s SPI device pins are working on the GPIO. I have ways to test the physical computing parts of a Raspberry Pi, and this is one of those tests that I just allow to keep running.

I’m using fish as my primary shell, so that I’ve defined a function in config.fish named stopsilly.

function stopsillyset -l silly_pid $(ps aux | grep silly_clock | grep -v grep | awk -F '[ ]+' '{print $2}')if string length -q -- $silly_pidkill --signal SIGINT $silly_pidelseecho silly_clock is not running.endend

The critical line in the function is line 2. I’m using awk to parse the line that ps and grep find if silly_clock is running. Awk will print out the process ID associated with the running silly_clock. Line 3 in the function looks to see if anything was found, meaning that silly_clock was running. If the process ID isn’t empty then line 4 sends a SIGINT to silly_clock, and silly_clock cleanly exits. If the process ID string is not found, meaning the string silly_pid is empty, then the else section says that silly_clock wasn’t running.

Links

Luma.LED_Matrix — https://github.com/rm-hull/luma.led_matrix

AWK — https://en.wikipedia.org/wiki/AWK

more work with linux mint 22 beta

I continued working with Linux Mint 22 beta today, changing the icons and setting up Python to my personal tastes. Here are a few interesting discoveries so far.

  • I tried to install Papirus Icon Theme only to discover it’s already there. I then went into Configure, Themes and changed the application icons to Papirus.
  • Python 3.12.3 is installed by default. That’s great. The version on LM 22β is only one minor point release behind official 3.12.4 Python. I did install the package python-is-python3 to be able to use bare python at the command line instead of python3. It’s time to move on from not having this as part of the default distribution. The only reason this was added was to support systems and users who had Python 2 still on their systems. Well, folks, Python 2 was sunset 1 January 2020, four-and-a-half years ago. It really is time to move on.
  • I needed to install pip with the apt package python3-pip because pip isn’t part of the default installation. Why?
  • My first attempt to install a Python package via pip produced that damned “This is an EXTERNALLY MANAGED” Python message. Who the hell thinks they can externally managed my personal system? I didn’t give anyone permission to do that. In any event I deleted the file /usr/lib/python3.12/EXTERNALLY-MANAGED, then installed the Python packages I wanted and needed. You know what pip did? It issued a message saying it installed the packages locally because I didn’t have rights to the global site-packages, which is what it should do. And I want those Python packages local, because when you install a Python package globally that’s broken then it causes all sorts of grief.
  • Speaking of broken Python global packages, powerline-status is broken in the Linux Mint base install, and has been for some time. You need to use sudo to pip uninstall poweline-status from the system site-package directory, then pip install poweline-status (no sudo!) to get a working copy locally installed. The correct and up-to-date powerline-status package will be installed down $HOME/.local/lib/python3.12/site-packages/powerline, and underneath that you’ll find bindings/fish/poweline-setup.fish (or bash/powerline-setup.sh for bash) that you can then source when an instance of your shell starts.

Before somebody in the peanut gallery pipes up that Linux is too hard, fine, it’s too hard for you. I live in Linux (and Unix) and can think of no other environment that’s any better, not even macOS, and certainly not Windows. I have written this ad nauseum but a bad day with Linux is far better than a good day with Windows, and as far as I’m concerned, there are no bad days with Linux unless I personally, royally, fucked up a Linux installation. And I have done that on occasion. Just read the second link below. But at least with Linux I could correct my royal fuck ups.

I haven’t seen anything at all in the beta I would consider a show stopper, or even a regular aggravation. The problems and issues I’ve encountered are easily overcome. I just wish I could get a version that ran on the Raspberry Pi 5.

Links

my linux mint 22 beta local installation

i did a very stupid thing and broke my linux mint graphical desktop