Open-source News

Phoronix Premium 2022 Christmas Deal For Enjoying Ad-Free Access, Single Page Articles

Phoronix - Mon, 12/19/2022 - 19:27
In the event you missed out on participating in last month's Black Friday deal for joining Phoronix Premium to enjoy the site ad-free and multi-page articles on a single page while helping to support continued operations of Phoronix, the deal has returned for Christmas week and marking the end of the year...

Linux 6.2 Landing Scalability Improvement For Large IBM Power Systems

Phoronix - Mon, 12/19/2022 - 18:50
The IBM Power/PowerPC architecture updates were sent out today for the ongoing Linux 6.2 merge window and most significant with this update is the introduction of a new Power-specific qspinlock implementation designed to bolster large system scalability...

AMD P-State EPP Patches Spun An 8th Time For Helping Out Linux Performance & Efficiency

Phoronix - Mon, 12/19/2022 - 18:27
AMD kicked off Christmas week by posting an eighth version of their P-State EPP driver patches for implementing the AMD Energy Performance Preference handling within their recent processors/SoCs for software to hint a performance or energy efficiency hint. P-State EPP can address some of the shortcomings with AMD's original P-State driver implementation merged nearly a year ago and has been showing good results in numbers posted by AMD engineers...

New Patches Aim To Boost Linux 9p Performance By ~10x

Phoronix - Mon, 12/19/2022 - 16:00
A new set of patches posted for the Plan 9 (9p) resource sharing protocol code inside the Linux kernel can deliver roughly 10x better performance for file transfers...

Use Rexx for scripting in 2023

opensource.com - Mon, 12/19/2022 - 16:00
Use Rexx for scripting in 2023 howtech Mon, 12/19/2022 - 03:00

In a previous article, I showed how the Rexx scripting language is both powerful and easy to use. It uses specific techniques to reconcile these two goals that are often considered in conflict.

This article walks you through two example Rexx scripts so you can get a feel for the language. Rexx purports to be highly capable yet easy to work with.

An example of a Rexx script

The LISP programming language is famous for its overuse of parentheses. It can be a real challenge for programmers to ensure they're all matched up correctly.

This short script reads a line of LISP code from the user and determines whether the parentheses in the input are properly matched. If the parentheses aren't properly balanced, the program displays a syntax error.

Below are three sample interactions with the program. In the first, the LISP code I entered was correctly typed. But the next two contain mismatched parentheses that the Rexx script identifies:

Enter a line to analyze: (SECOND (LAMBDA (LIS) (FIRST (CDR LIS)) )) Parentheses are balanced Enter a line to analyze: ((EQSTR (CAR LIS1) (CAR LIS2)) Syntax error: too many left parens, not balanced Enter a line to analyze: (EQSTR (CAR LIS1) CAR LIS2)) Syntax error: right paren before or without left paren

Here's the Rexx program:

counter = 0 /* counts parentheses */ say 'Enter a line to analyze:' /* prompts user for input */ pull input_string /* reads line of user input */ length_of_string = length(input_string) /* process each character of the input line, one at a time */ do j = 1 to length_of_string while counter >= 0 character = substr(input_string,j,1) if character = '(' then counter = counter + 1 if character = ')' then counter = counter - 1 end /* display the appropriate message to the user */ if counter = 0 then say 'Parentheses are balanced' else if counter < 0 then say 'Syntax error: right paren before or without left paren' else say 'Syntax error: too many left parens, not balanced'

Programming and development Red Hat Developers Blog Programming cheat sheets Try for free: Red Hat Learning Subscription eBook: An introduction to programming with Bash Bash shell scripting cheat sheet eBook: Modernizing Enterprise Java An open source developer's guide to building applications

First, the program prompts the user to enter a line of input with the say instruction. Then it reads it with a pull instruction.

The say and pull  instructions are used for conversational input/output, or direct interaction with users. Rexx also supports character-oriented and line- or record- oriented I/O.

Next, the script uses the length function to place the length of the input line into the variable length_of_string.

The do loop processes each character from the input line, one at a time. It increments the counter each time it encounters a left parenthesis, and decrements it each time it recognizes a right parenthesis.

If the counter ends up as zero after processing the entire input line, the program knows that any parentheses in the input line match up correctly. If the counter is not 0 after processing, the input line has mismatched parentheses.

The final if statements display the proper message to the user. One could code these if statements in any number of styles, as per individual preference. (The main requirement is that whenever multiple statements are coded within a branch, they must be enclosed in a do...end group.)

This program shows that Rexx is free-form and case-insensitive. It does not rely on reserved words, so you're free to use common words like counter or character to represent variables.

The one key requirement Rexx does impose is that any function must immediately be followed by a left parenthesis. Examples in the program are the length and substr functions. Put a space between a function name and its following parenthesis, and Rexx won't recognize the function.

Outside of a few minimal requirements like these, Rexx requires very little from the programmer in terms of syntax, special characters, or restrictive coding rules.

Rexx programs look and read like pseudo-code. This makes them relatively easy to read and work with.

A real-world example of a Rexx script

Here's a program from the real world:

Les Koehler, a Rexx user, had a legacy accounting program that matched accounting records on hand against those that a vendor sent to him daily. The legacy program ran for several hours every day to process 25,000 records. It employed a sequential "walk the list" technique to match one set of records against the other.

Les replaced the legacy program with a Rexx script. The Rexx script performs matching by using associative arrays:

/* Create an associative array reflecting */ /* the values in the first list of names */ /* by Les Koehler */ flag. = 0 /* Create array, set all items to 0 */ do a = 1 to list_a.0 /* Process all existing records */ aa = strip(list_a.a) /* Strip preceding/trailing blanks */ flag.aa = 1 /* Mark each record with a 1 */ end /* Try to match names in the second list */ /* against those in the associative array */ m = 0 /* M counts number of missing names */ do b = 1 to list_b.0 /* Look for matching name from LIST_B */ bb = strip(list_b.b) /* Put LIST_B name into variable BB */ if \ flag.bb then do /* If name isn't in FLAG array */ m = m+1 /* add 1 to count of missing names */ missing.m = bb /* add missing name to MISSING array */ end end missing.0 = m /* Save the count of unmatched names */

Les was able to reduce processing time from several hours down to a matter of seconds.

The first line of code (flag. = 0) creates a new array called flag and initializes every element in that array to 0.

The array list_a contains all the existing accounting records. Its first element (list_a.0) by convention contains the number of elements in the array.

So the first do loop processes all elements in the array of existing records (list_a) and marks each of them as existing in the flag array. The statement flag.aa = 1 marks the content-addressable item in the flag array as present.

The second do loop peddles through each item in the set of new records, contained in the array called list_b.

The if statement checks whether an item from the second array of records is marked present in the flag array. If not, the program increments the number of items present in the new list of accounting records that do not exist in the old list of records. And it puts the missing item into the missing array: missing.m = bb.

The final statement (missing.0 = m) simply updates the number of items in the missing array, by convention stored in array position 0.

Rexx improvements

Why is this Rexx program so fast compared to the legacy code it replaces? First, the associative arrays allow direct lookup of a new record against the old records. Direct access is much faster than the sequential "walk-the-list" technique it replaced.

Secondly, all the array elements reside in memory. Once the files of the old and new accounting records have been initialized into the Rexx arrays, no further disk I/O is needed. Disk I/O is always orders of magnitude slower than memory access.

A Rexx array expands as much as memory allows. This script takes advantage of modern computers with seemingly endless amounts of RAM, and frees the programmer from managing memory.

Conclusion

I hope these two simple programs have shown how easy Rexx is to read, write, and maintain. Rexx is designed to put the burden of programming on the machine instead of the programmer. Yet the language still has plenty of power, due to the design techniques I've described in this series of articles.

For free Rexx downloads, tools, tutorials, and more, visit RexxInfo.org. You can join the Rexx Language Association for free.

This article is dedicated to the memory of Les Koehler, who was active with Rexx and the Rexx community since their very earliest days.

Here are two simple programs to show how easy Rexx is to read, write, and maintain.

Image by:

WOCinTech Chat. Modified by Opensource.com. CC BY-SA 4.0

Programming What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

How I use my old camera as a webcam with Linux

opensource.com - Mon, 12/19/2022 - 16:00
How I use my old camera as a webcam with Linux tomoliver Mon, 12/19/2022 - 03:00

This year after largely abandoning my MacBook in favor of a NixOS machine, I started getting requests to "turn my camera on" when video calling people. This was a problem because I didn't have a webcam. I thought about buying one, but then I realized I had a perfectly good Canon EOS Rebel XS DSLR from 2008 lying around on my shelf. This camera has a mini-USB port, so naturally, I pondered: Did a DSLR, mini-USB port, and a desktop PC mean I could have a webcam?

There's just one problem. My Canon EOS Rebel XS isn't capable of recording video. It can take some nice pictures, but that's about it. So that's the end of that.

Or is it?

There happens to be some amazing open source software called gphoto2. Once installed, it allows you to control various supported cameras from your computer and it takes photos and videos.

Supported cameras

First, find out whether yours is supported:

$ gphoto2 --list-camerasCapture an image

You can take a picture with it:

$ gphoto2 --capture-image-and-download

The shutter activates, and the image is saved to your current working directory.

Capture video

I sensed the potential here, so despite the aforementioned lack of video functionality on my camera, I decided to try gphoto2 --capture-movie. Somehow, although my camera does not support video natively, gphoto2 still manages to spit out an MJPEG file!

On my camera, I need to put it in "live-view" mode before gphoto2 records video. This consists of setting the camera to portrait mode and then pressing the Set button so that the viewfinder is off and the camera screen displays an image. Unfortunately, though, this isn't enough to be able to use it as a webcam. It still needs to get assigned a video device, such as /dev/video0.

Install ffmpeg and v4l2loopback

Not surprisingly, there's an open source solution to this problem. First, use your package manager to install gphoto2, ffmpeg, and mpv. For example, on Fedora, CentOS, Mageia, and similar:

$ sudo dnf install gphoto2 ffmpeg mpv

On Debian, Linux Mint, and similar:

$ sudo apt install gphoto2 ffmpeg mpv

I use NixOS, so here's my configuration:

# configuration.nix
...
environment.systemPackages = with pkgs; [
  ffmpeg
  gphoto2
  mpv
...

Creating a virtual video device requires the v4l2loopback Linux kernel module. At the time of this writing, that capability is not included in the mainline kernel, so you must download and compile it yourself:

$ git clone https://github.com/umlaeute/v4l2loopback

$ cd v4l2loopback

$ make

$ sudo make install

$ sudo depmod -a

If you're using NixOS like me, you can just add the extra module package in configuration.nix:

[...]
boot.extraModulePackages = with config.boot.kernelPackages;
[ v4l2loopback.out ];
boot.kernelModules = [
  "v4l2loopback"
];
boot.extraModprobeConfig = ''
  options v4l2loopback exclusive_caps=1 card_label="Virtual Camera"
'';
[...]

On NixOS, run sudo nixos-rebuild switch and then reboot.

Create a video device

Assuming your computer currently has no /dev/video device, you can create one on demand thanks to the v4l2loopback.

Run this command to send data from gphoto2 to ffmpeg, using a device such as /dev/video0 device:

$ gphoto2 --stdout --capture-movie |
 ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video0

You get output like this:

ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11.3.0 (GCC)
  configuration: --disable-static ...
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Capturing preview frames as movie to 'stdout'. Press Ctrl-C to abort.
[mjpeg @ 0x1dd0380] Format mjpeg detected only with low score of 25, misdetection possible!
Input #0, mjpeg, from 'pipe:':
  Duration: N/A, bitrate: N/A
  Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 768x512 ...
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> rawvideo (native))
[swscaler @ 0x1e27340] deprecated pixel format used, make sure you did set range correctly
Output #0, video4linux2,v4l2, to '/dev/video0':
  Metadata:
    encoder         : Lavf58.76.100
  Stream #0:0: Video: rawvideo (I420 / 0x30323449) ...
    Metadata:
      encoder         : Lavc58.134.100 rawvideo
frame=  289 fps= 23 q=-0.0 size=N/A time=00:00:11.56 bitrate=N/A speed=0.907x

To see the video feed from your webcam, use mpv:

$ mpv av://v4l2:/dev/video0 --profile=low-latency --untimed Image by:

(Tom Oliver, CC BY-SA 4.0)

Start your webcam automatically

It's a bit annoying to execute a command every time you want to use your webcam. Luckily, you can run this command automatically at startup. I implement it as a systemd service:

# configuration.nix
...
  systemd.services.webcam = {
    enable = true;
    script = ''
      ${pkgs.gphoto2}/bin/gphoto2 --stdout --capture-movie |
        ${pkgs.ffmpeg}/bin/ffmpeg -i - \
            -vcodec rawvideo -pix_fmt yuv420p -f v4l2  /dev/video0
    '';
wantedBy = [ "multi-user.target" ];
  };

...

On NixOS, run sudo nixos-rebuild switch and then reboot your computer. Your webcam is on and active.

To check for any problems, you can use systemctl status webcam. This tells you the last time the service was run and provides a log of its previous output. It's useful for debugging.

More Linux resources Linux commands cheat sheet Advanced Linux commands cheat sheet Free online course: RHEL technical overview Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles Iterating to make it better

It's tempting to stop here. However, considering the current global crises, it may be pertinent to wonder whether it's necessary to have a webcam on all the time. It strikes me as sub-optimal for two reasons:

  1. It's a waste of electricity.
  2. There are privacy concerns associated with this kind of thing.

My camera has a lens cap, so to be honest, the second point doesn't really bother me. I can always put the lens cap on when I'm not using the webcam. However, leaving a big power-hungry DSLR camera on all day (not to mention the CPU overhead required for decoding the video) isn't doing anything for my electricity bill.

The ideal scenario:

  • I leave my camera plugged in to my computer all the time but switched off.
  • When I want to use the webcam, I switch on the camera with its power button.
  • My computer detects the camera and starts the systemd service.
  • After finishing with the webcam, I switch it off again.

To achieve this, you need to use a custom udev rule.

A udev rule tells your computer to perform a certain task when it discovers that a device has become available. This could be an external hard drive or even a non-USB device. In this case, you need it to recognize the camera through its USB connection.

First, specify what command to run when the udev rule is triggered. You can do that as a shell script (systemctl restart webcam should work). I run NixOS, so I just create a derivation (a Nix package) that restarts the systemd service:

# start-webcam.nix
with import <nixpkgs> { };

writeShellScriptBin "start-webcam" ''
  systemctl restart webcam
  # debugging example
  # echo "hello" &> /home/tom/myfile.txt
  # If myfile.txt gets created then we know the udev rule has triggered properly
''

Next, actually define the udev rule. Find the device and vendor ID of the camera. Do this by using the lsusb command. That command is likely already installed on your distribution, but I don't use it often, so I just install it as needed using nix-shell:

$ nix-shell -p usbutils

Whether you already have it on your computer or you've just installed it, run lsusb:

$ lsusb
Bus 002 Device 008: ID 04a9:317b Canon, Inc. Canon Digital Camera
[...]

In this output, the vendor ID is 04a9 and the device ID is 317b. That's enough to create the udev rule:

ACTION=="add", SUBSYSTEM=="usb",
ATTR{idVendor}=="04a9",
ATTR{idProduct}=="317b",
RUN+="/usr/local/bin/start-webcam.sh"

Alternatively, if you're using NixOS:

# configuration.nix
[...]
let
  startWebcam = import ./start-webcam.nix;
[...]
services.udev.extraRules = ''
  ACTION=="add",  \
  SUBSYSTEM=="usb", \
  ATTR{idVendor}=="04a9", \
  ATTR{idProduct}=="317b",  \
  RUN+="${startWebcam}/bin/start-webcam"
'';
[...]

Finally, remove the wantedBy = ["multi-user.target"]; line in your start-webcam systemd service. (If you leave it, then the service starts automatically when you next reboot, whether the camera is switched on or not.)

Reuse old technology

I hope this article has made you think twice before chucking some of your old tech. Linux can breathe life back into technology, whether it's your computer or something simple like a digital camera or some other peripheral.

I gave my old DSLR camera new life with gphoto2 by turning it into a webcam for my Linux computer.

Image by:

Internet Archive Book Images. Modified by Opensource.com. CC BY-SA 4.0

Linux Hardware What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Discover the power of the Linux SpaceFM file manager

opensource.com - Mon, 12/19/2022 - 16:00
Discover the power of the Linux SpaceFM file manager sethkenlon Mon, 12/19/2022 - 03:00

SpaceFM is a tabbed file manager for Linux using the GTK toolkit, so it fits right in on desktops like GNOME, Mate, Cinnamon, and others. SpaceFM also features a built-in device manager system, so it's particularly good for window managers, like Fluxbox or fvwm, which typically don't include a graphical device manager. If you're happy with the file managers on Linux, but you want to try one that's a little bit different in design, SpaceFM is worth a look.

Install SpaceFM

On Linux, you're likely to find SpaceFM in your distribution's software repository. On Fedora, Mageia, OpenMandriva, and similar:

$ sudo dnf install spacefm

On Debian and Debian-based systems:

$ sudo apt install spacefmPanels

I don't know why SpaceFM is called SpaceFM, but it could be because it makes a concerted effort to let you use every bit of space in its window for something useful. By default, SpaceFM is actually pretty simple, standard-issue file manager. It has a single panel listing your files, a toolbar, and a menu bar.

Image by:

(Seth Kenlon, CC BY-SA 4.0)

All the "usual" rules apply.

  • Double-click to open a directory or to open a file in its default application.

  • Right-click for a contextual menu providing lots of standard options (copy, paste, rename, view properties, create a new folder, and so on).

The way SpaceFM sets itself apart, though, is its panel system. SpaceFM displays one panel by default. That's the big file window listing your files. But it can have up to four panel views, plus a few bonus panels for some specific tasks.

More Linux resources Linux commands cheat sheet Advanced Linux commands cheat sheet Free online course: RHEL technical overview Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles Opening a new panel

Instead of seeing one directory in your file manager, you can see two. To bring up another directory in its own pane, press Ctrl+2 or go to the View menu and select Panel 2. Alternatively, click the second green dot icon from the left in the menu panel.

With two panels, you can move files from one directory to another without opening a new file manager window, or you can browse two directories to compare their contents.

But why settle for two panels? Maybe you'd rather see three directories at once. To bring up a third directory in a dedicated pane, press Ctrl+3 or go to the View menu and select Panel 3. Alternatively, click the third green dot icon from the left in the menu panel. This panel appears at the bottom of the SpaceFM window.

With three panels open, you can move files between several directories, or sort files from a common "dumping ground" (like your Desktop or Downloads folder) into specific directories.

Of course, once you've tried three panels you'll probably find yourself itching for a fourth. To open a fourth directory in its own pane, press Ctrl+4 or go to the View menu and select Panel 4. Alternatively, click the fourth green dot icon from the left in the menu panel. This one opens next to Panel 3, splitting your SpaceFM window into even quarters.

Image by:

(Seth Kenlon, CC BY-SA 4.0)

What about a fifth panel? Well, actually SpaceFM stops at four panels. If you really do want a fifth panel, you have to open a new SpaceFM window. However, there are still more panels, used for information other than file listings, to explore.

Special panels

The View menu reveals that in addition to file panels, there are additionally task-specific panels you can choose to display. This includes:

  • Task manager: Lists ongoing file manager processes. This isn't a general-purpose task manager, so to set nice values or detect a zombie apocalypse of undead PIDs, htop or top is still your utility of choice.

  • Bookmarks: Links to common folders, such as Desktop, Documents, Downloads, and any location you want to keep handy.

  • Devices: USB thumb drives and remote file systems.

  • File tree: A view of your file system in order of directory inheritance.

These panels open on the left side of SpaceFM, but they do stack. You can have bookmarks, devices, tasks, and a file tree open at once, although it helps to have a very tall SpaceFM window.

Make space for SpaceFM

SpaceFM is a configurable multi-tasking file manager. It maximizes the information you can build into a single window, and it lets you decide what's important, and when. This article has focused on the panels of SpaceFM because those are, at least in my view, the most unique aspect of the application. However, there's a lot more to SpaceFM, including plugins, preferences, a design mode, keyboard shortcuts, and customization. This isn't a small application, even though it is a lightweight one. Spend some time with SpaceFM, because you never know what you'll discover.

If you're happy with the file managers on Linux, but you want to try one that's a little bit different in design, SpaceFM is worth a look.

Image by:

Opensource.com

Linux What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Most Commonly Asked Questions in Linux Interviews

Tecmint - Mon, 12/19/2022 - 15:14
The post Most Commonly Asked Questions in Linux Interviews first appeared on Tecmint: Linux Howtos, Tutorials & Guides .

If you have already achieved your Linux certification and are looking forward to securing a Linux job, it pays a great deal to prepare for an interview that tests your knowledge of the ins

The post Most Commonly Asked Questions in Linux Interviews first appeared on Tecmint: Linux Howtos, Tutorials & Guides.

Pages