r/linux_programming • • Dec 12 '18

How do I get a line from a text file and use it as a parameter for a bash command?

6 Upvotes

I have a text file where each line is a file path that has to be used as a parameter to a bash command. How do I do that? How do I get the line to use as a parameter? Basically, this is what I need to do:

command line1
command line2
command line3
etc. until the end of the document

Also, I expect each command to take a long time, so I want to use screen to detach from the screen and let it keep running while I do other stuff, so, I think I need to multiplex or something? I don't know/remember how to do that. Any help would be greatly appreciated.


r/linux_programming • • Oct 20 '17

How Task Familiarity Affects Software Estimates

Thumbnail
chrismm.com
6 Upvotes

r/linux_programming • • May 23 '17

Java Tutorial on Linux

Thumbnail
youtube.com
6 Upvotes

r/linux_programming • • Mar 14 '17

I want to learn to code in linux, any advice?

Thumbnail
google.com
6 Upvotes

r/linux_programming • • Feb 01 '17

Learn LCD and LXC Linux Containers

Thumbnail
youtu.be
6 Upvotes

r/linux_programming • • Oct 31 '16

Finding bugs in the code of LLVM project with the help of PVS-Studio

Thumbnail
viva64.com
6 Upvotes

r/linux_programming • • Oct 10 '16

Working with Firewalld

Thumbnail
hostpresto.com
6 Upvotes

r/linux_programming • • Jul 08 '16

Decoding and playing audio file in Linux

Thumbnail enise.org
6 Upvotes

r/linux_programming • • Oct 25 '15

The kernel connection multiplexer

Thumbnail
lwn.net
6 Upvotes

r/linux_programming • • Aug 30 '15

release GDB 7.10 released! Improvements for scripting, shared libraries on remote targets. Reverse debugging support on ARM64. Support for dtrace probes.

Thumbnail sourceware.org
6 Upvotes

r/linux_programming • • Aug 15 '15

release The GNU C Library version 2.22 is now available

Thumbnail sourceware.org
6 Upvotes

r/linux_programming • • Feb 07 '15

release The GNU C Library version 2.21 is now available

Thumbnail sourceware.org
6 Upvotes

r/linux_programming • • Oct 28 '14

Why Are My Page_faults So High in Perf?

Thumbnail sdf.org
6 Upvotes

r/linux_programming • • Aug 21 '14

Ftrace: The hidden light switch

Thumbnail
lwn.net
6 Upvotes

r/linux_programming • • Feb 21 '14

Systemd programming part 2: activation and language issues

Thumbnail
lwn.net
6 Upvotes

r/linux_programming • • Dec 20 '25

Running man page documentation of a git branch

5 Upvotes

I want to open a PR to fix a few typos in the man pages of a popular linux library, anyhow I'm not well versed in the linux ecosystem development. My expectations would be to write the changes to the man pages in my branch and then run a local copy of the output to verify everything is ok. I found out how to run custom man documentation, but it seems man wants a gz archive and I'm not sure how to produce it. My questions are:

  • How can I visualize the man pages of the local branch version?

  • Is there a compilation step for man pages?

  • Are my expectations right? Or should I follow a different workflow?


r/linux_programming • • Nov 24 '25

I wrote a kernel memory allocator in the userspace based on the original slab allocator paper

Thumbnail
github.com
5 Upvotes

objcache is an object caching slab memory allocator that is based on the original paper by Jeff Bonwick. I have tried to implement some of the interesting ideas shared in the paper. This is my learning project and would really appreciate your feedback and review. Thanks!


r/linux_programming • • Apr 17 '25

How would someone go about creating a clipboard manager

5 Upvotes

I am trying to make a clipboard manager in C. It is for an OS course project. I have used C language, but this is the first time I would be making this kind of thing. Can anyone maybe point to the relevant information as to where I should get started with this and like give me a sort of roadmap?


r/linux_programming • • Feb 24 '25

LD_PRELOAD Hook only logging a few commands on Ubuntu 20.04.3 LTS

5 Upvotes

I have written this following code:

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dlfcn.h>
#include <time.h>

// Log file location
#define LOG_FILE "/home/maifee/cmd-log.log"

// Function to get the process name
void get_process_name(pid_t pid, char *name, size_t len) {
    char path[256];
    snprintf(path, sizeof(path), "/proc/%d/comm", pid);
    FILE *file = fopen(path, "r");
    if (file) {
        fgets(name, len, file);
        name[strcspn(name, "\n")] = 0; // Remove newline character
        fclose(file);
    } else {
        strncpy(name, "unknown", len);
    }
}

// Override execve
int execve(const char *filename, char *const argv[], char *const envp[]) {
    // Get the original execve function
    int (*original_execve)(const char *, char *const[], char *const[]) = dlsym(RTLD_NEXT, "execve");

    // Log the command to a file
    FILE *log_file = fopen(LOG_FILE, "a");
    if (log_file) {
        pid_t pid = getpid();
        pid_t ppid = getppid();
        char pname[256], ppname[256];
        get_process_name(pid, pname, sizeof(pname));
        get_process_name(ppid, ppname, sizeof(ppname));
        // print time [2025.12.30 23:59:59]
        time_t t = time(NULL);
        struct tm tm = *localtime(&t);
        fprintf(log_file, "[%d.%d.%d %d:%d:%d] ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
        fprintf(log_file, "PID: %d (%s), PPID: %d (%s), Command: ", pid, pname, ppid, ppname);
        for (int i = 0; argv[i]; i++) {
            fprintf(log_file, "%s ", argv[i]);
        }
        fprintf(log_file, "\n");
        fclose(log_file);
    }

    // NEVER call execve directly, it will cause an infinite loop
    // NEVER remove this line
    return original_execve(filename, argv, envp);
}

And I compile it using the following command:

gcc -shared -fPIC -o ld_preload_hook.so ld_preload_hook.c -ldl

And then I set the LD_PRELOAD environment variable to the path of the shared object file:

export LD_PRELOAD=$PWD/ld_preload_hook.so

And then I reload the shell:

source ~/.zshrc
source ~/.bashrc

And it generates the log file, which is great. But the issue is it just generate these few specific commands:

[2025.2.25 1:30:43] PID: 8062 (lesspipe), PPID: 8061 (lesspipe), Command: basename /usr/bin/lesspipe 
[2025.2.25 1:30:43] PID: 8064 (lesspipe), PPID: 8063 (lesspipe), Command: dirname /usr/bin/lesspipe 
[2025.2.25 1:32:39] PID: 9658 (lesspipe), PPID: 9657 (lesspipe), Command: basename /usr/bin/lesspipe 
[2025.2.25 1:32:39] PID: 9660 (lesspipe), PPID: 9659 (lesspipe), Command: dirname /usr/bin/lesspipe 

That's all I tried restarting my device, restarting the shell again. Nothing works. Tried ls, dir and many other commands.

But the result stays the same. I am using Ubuntu 20.04.3 LTS. I am not sure what I am doing wrong. Can anyone help me with this? I am just learning hooks by implementing, right now.


r/linux_programming • • Oct 21 '24

Am I wrong or is steam wrong?

5 Upvotes

Ok so I have this status-script written in python for i3bar that, among other things, checks the network usage.

It uses the following function to look that up:

def network_usage(interface_name: str) -> str:
    with open("/sys/class/net/%s/statistics/rx_bytes" %interface_name) as fp_rx, \
         open("/sys/class/net/%s/statistics/tx_bytes" %interface_name) as fp_tx:
        pol1_ts = time_ns()
        rx_bytes_old: int = int(fp_rx.read())
        tx_bytes_old: int = int(fp_tx.read())
    sleep(0.25)
    with open("/sys/class/net/%s/statistics/rx_bytes" %interface_name) as fp_rx, \
         open("/sys/class/net/%s/statistics/tx_bytes" %interface_name) as fp_tx:
        pol2_ts = time_ns()
        rx_bytes_new: int = int(fp_rx.read())
        tx_bytes_new: int = int(fp_tx.read())
    rx_bytes_ps: float = (rx_bytes_new - rx_bytes_old) / ((pol2_ts - pol1_ts) / (10**9))
    tx_bytes_ps: float = (tx_bytes_new - tx_bytes_old) / ((pol2_ts - pol1_ts) / (10**9))
    byte_parser = lambda x:                              \
        f"{round(x)} BPS"            if x < 1000    else \
        f"{round(x / 1000)} KBPS"    if x < 1000**2 else \
        f"{round(x / 1000**2)} MBPS" if x < 1000**3 else \
        f"{round(x / 1000**3)} GBPS"
    return f"in {byte_parser(rx_bytes_ps)} - out {byte_parser(tx_bytes_ps)}"

Now, what I noticed is that the output of this function, is always a factor of 10 removed from the network usage Steam shows (e.g. if my script outputs 3 MBPS steam shows something like 27.8 MBps).
So is my math just wrong? (if so how exactly cause I'm stuck) or do the [r|t]x_bytes work differently than what this function assumes?

Sorry for the noobish question, thanks in advance!
(if it matters I'm using Debian 12.something)


r/linux_programming • • Sep 28 '24

Shell scripting basics

5 Upvotes

Hi all, I’m a comp sci student with most of my experience in c++ but a decent amount of experience with command line and I’m looking to get into shell scripting to learn software development better, especially at a root level

Any advice or resources I can use to learn more would be appreciated!

TLDR: looking to learn shell scripting, unsure where to start


r/linux_programming • • Jan 08 '24

Tabula games are now supported at bgammon.org (free backgammon service without ads)

Thumbnail bgammon.org
5 Upvotes

r/linux_programming • • Dec 18 '23

driver build does not find orc_types.h from arch/x86/include

5 Upvotes

This is a cross post from stack overflow; I didn't get any nibbles there, so thought I'd try here.

The short version is the kernel build portion of building a driver for special hardware fails when trying to find orc_types.h. The file does exist, but in /usr/src/kernels/5.8blah/arch/x86/include... (btw, I'm not typing out the full directory name; 5.8blah (and whatever I type below) really refers to 5.8.18-100.fc31.x86_64)

I'm looking for reasons why the build won't complete / what I'm doing wrong.

The longer version is: I need to build the driver for an older version of Fedora and the manufacturer stopped linux support at kernel 2.6. It builds fine in Fedora 23 as is. I successfully ported it to F28 which was kernel ver 4, and now need to get it on to kernel ver 5 in Fedora 31.

I have F31 installed on new hardware (Intel i7) and started the driver port after installing the kernel souce and some other utilities ( yum install's of kernel-devel, elfutils-libelf-devel, and gcc). Once I started the build I found that I also needed make, flex and bison which I did just by making calls to the program and the OS magically asked then installed those funcitons. All this to say I'm not really a Linux guy and could well have messed any of these up or not configured them properly.

The manufacture's makefiles have required some modification and I may have messed that up as well. But assuming I did it mostly correct, the build starts with compiling a bunch of kernel source in /usr/src/kernels/5.8xxx. Some files were compiled (in 5.8blah/arch/x86/tools and 5.8blah/scripts/kconfig) but it gagged at ./scripts/sorttable.c trying to include <asm/orc_types.h>. I found that file in /usr/src/kernels/5.8blah/arch/x86/include/asm.

But why does the compiler not find it? Am I missing an environment variable? Do I need a link to that directory? Do I need to modify the makefile with something like an ARCH argument? Am I missing a confguration step with the compiler set up? What?


r/linux_programming • • Sep 30 '23

Hello, I would like to make sure that this Laptop supports Fedora.

5 Upvotes

Hello, I would like to make sure that this Laptop supports Fedora.  I found out that it only had RHEL and Ubuntu Certification (https://ubuntu.com/certified/202309-32038), but not Fedora. So my question is will Fedora 100% work on it without any problems? https://psref.lenovo.com/Product/ThinkPad/ThinkPad_P16v_Gen_1_AMD  I plan to use Fedora Onyx or Fedora Kinoite. Product id: 21FE000VCK