Questions tagged [linux]
Use this tag for code that specifically targets the Linux operating system (consider [unix] for more portable code that should run on other Unix-like systems).
573 questions
11
votes
4
answers
1k
views
A simple server-client application in C
I am reading "The Linux Programming Interface" by Michael Kerrisk. I'm studying about sockets, and I made a simple application using sockets on the unix domain.
I want to know if I'm using ...
8
votes
1
answer
618
views
Shared-Memory Queue Implementation in C
Recently I am working on implementing a shared-memory based IPC message queue in C programming language on Linux system. A few design choices I've made include
The queue will have only 1 producer, ...
3
votes
0
answers
61
views
library variant during application startup
I wrote some PoC for load library with best optimization version during application startup. The goal for it check in the _init function code checking by cpuid ...
8
votes
2
answers
478
views
Disabling local accounts on Azure Linux virtual machines
We’re enforcing Azure Entra authentication across all Linux VMs, so we’ll disable all local accounts via a custom script. The script will also create a single “break-glass” user with a randomly ...
2
votes
1
answer
237
views
CoLib - A C++ Coroutine Library in a Single Header
I've developed a coroutine library for C++ that is contained within a single header file. It is compatible with both Windows and Linux platforms. This library is not multi-threaded; instead, it is ...
2
votes
1
answer
69
views
NodeJS discord bot that starts systemd services
I am writing a discord bot that can start and stop my minecraft server. It currently works, but I am still learning NodeJS and I could use some tips on how to optimize my code.
Calling a command will ...
4
votes
3
answers
293
views
Calculation of consumed resources by subprocess
I've created a script that executes arbitrary user code in Python, written in a .py file, and returns execution result (contents of stdout, stderr, exec code) + ...
7
votes
3
answers
1k
views
C++ code reading from a text file, storing value in int, and outputting properly rounded float
Late important updates (unified)
I found, that on my Pi's Debian 12 Bookworm (arm64), there is just an older g++-12 available. ...
3
votes
1
answer
195
views
How to refactor this (sort of) getline implementation?
Goals:
Create a function char *get_next_line(int fd) such as:
Repeated calls (e.g., using a loop) to your get_next_line() ...
5
votes
2
answers
154
views
Bash Script for Docker Image Cleanup
I’ve been working on a bash script to clean up old Docker images while keeping the latest tag for each repository and skipping images currently in use. I’m sharing the script below and would ...
3
votes
0
answers
116
views
MIDI router in Rust
I am working on a small MIDI router application for the Jack audio connection kit in Rust. The goal of the application is to route MIDI signals from an instrument to one or multiple applications in ...
5
votes
1
answer
109
views
Re-implementing head in x86-64 assembly targeting linux
I'm pretty new to x64 programming and tried to recreate parts of head for study (targeting linux).
Are there any stylistic issues?
The head function uses a buffer ...
0
votes
1
answer
104
views
Rust code to print shell prompt
I'm new to Rust, and this is my first successful significant Rust code. It prints a prompt(which is technically a string) to the console.
I'm struggling with concepts like ...
6
votes
1
answer
201
views
Function for listing processes holding a specified file open
The function's prototype is:
int processes_using(const char *name, pid_t pidlist[], int size)
It searches through all processes it can to find any that have an ...
3
votes
1
answer
257
views
An example of hello world LKM
In 2021 I spent a lot of time studying low-level in Linux, as I'm a low-level addict in general, I only now decided to change my area to introduce myself to the market, and I wrote a repository on ...
4
votes
3
answers
858
views
Implementing strscpy(): Is using errno as a negative return value a bad practice?
strscpy() is similar to the standard strncpy() except that it always writes a valid null-terminated string (unless ...
1
vote
1
answer
130
views
Linux terminal like parsing
I'm creating a program that will hopefully operate like linux terminal (basic commands) for learning purposes.
...
8
votes
4
answers
1k
views
3
votes
2
answers
214
views
5
votes
1
answer
363
views
A simple mmap(2) wrapper
I've written a wrapper for the mmap syscall. It's quite limited in functionality at the moment (there are lots of flags to support) but it's sufficient for mapping ...
-1
votes
1
answer
69
views
5
votes
3
answers
826
views
Implementation of recursive `ls` utility
Recently I wrote my own implementation of a utility for recursive output of the directories' contents, kind of similar to the ls Linux utility with the ...
4
votes
1
answer
81
views
Debian and Docker compose upgrade script, 2nd version
As a continuation of this question, I would like a second review from you.
Here is the updated sh script:
...
4
votes
1
answer
504
views
Single threaded epoll based coroutine library for C++, Linux
I've implemented a small single-header library over the C++20 coroutines. This library only works on a single thread and it is limited to Linux because it is also based on epoll.
The library does not ...
5
votes
2
answers
450
views
Parsing gateway ip from `/proc/net/route` in a docker container
In try to replicate the outcome of the following command sequence using php:
netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10
I did this using ...
4
votes
2
answers
357
views
LKM: Extract cpu model name from /proc/cpuinfo
I wrote a small LKM that opens the /proc/cpuinfo file, reads it line by line, and attempts to the cpu model name.
If the function fails to extract the cpu model ...
3
votes
1
answer
438
views
Shell script to download multiple files from different URL's using for loop to download and verify files on each invocation
The expected behavior of the script is to download a file from a URL if the file is not present in the current directory and compare the md5 checksum of the file against the md5 checksum from the ...
0
votes
0
answers
38
views
For loop to download files once and verify them on each invocation [duplicate]
The complete script works as expected. I am able to download and verify the files. If the file is all ready present verification is retested and downloads if necessary.
I'm in the process of teaching ...
2
votes
2
answers
168
views
Linux Script Set Permission Function
I wrote a simple script to set permissions for a file or folder for some embedded Linux devices as part of a larger setup script.
This method would be called on less than 20 files and folders. It ...
5
votes
1
answer
190
views
Processing large blocklists with GNU Parallel
This is an ongoing project that has undergone a major update to speed up list processing. Here is the homepage for anyone interested.
It processes lists defined in ...
4
votes
1
answer
50
views
Improving Shell Installation Script
I'm currently working on a project and currently have this code. I already improved it by having some pointers, but I want to make it more professional looking and right. What should I implement next?
...
2
votes
1
answer
192
views
Bash script that installs Arch Linux
I wrote a bash script that installs Arch Linux. I wanted to simplify the installation of the Arch Linux system by automating things like setting locale, hostname, networking, etc. This is my second ...
2
votes
0
answers
83
views
a C/Python X server interface extension package
The project is named winlin; it's a portmanteau of the words window and Linux.
I'm working on a CPython extension to interact with the X server and manipulate windows. I don't have a ton of ...
5
votes
1
answer
197
views
Creating ZFS-based rootfs for installing Linux in Bash
I've written a bash script that creates a root filesystem on ZFS for installing Debian or Arch. The purpose of this script is to make it easier installing e.g. Arch without the need to make a ZFS pool ...
5
votes
2
answers
678
views
RAII POSIX process created by fork
By analogy with std::thread, I've written an RAII POSIX process:
...
3
votes
2
answers
105
views
Archive, compress, remove old archive file then remove source file if below set size
I'm working on a script that will archive, compress, clear old archive files, then remove the source file if it is below a set size. The output when I tested it worked, but I just wanted a second ...
4
votes
3
answers
512
views
A shell script to get the current battery status
Is this code well written? I'm not doing much, just rendering my battery status for my status bar but the code seems pretty long. I am new to Bash and Linux, so I thought this code could be improved ...
2
votes
1
answer
288
views
Multiply two huge base-10 numbers in assembly
This post is a second part of my original post, Add two huge base-10 numbers, which deals with adding two huge base-10 numbers. However, in this case, I'm multiplying two non-negative whole numbers. ...
3
votes
1
answer
58
views
DmenuWacom: a front hand for wacom tablets
DmenuWacom
During my raids, I came across and solved several problems, obviously in my style, very similar to the suckless.org approach and which still works quite well. In fact, I started writing a ...
5
votes
1
answer
207
views
declarative package manager for Arch Linux
pacdef is my declarative package manager for Arch Linux. I have written it since I often found myself discovering a new tool at one of my PCs, using it there for a ...
5
votes
1
answer
198
views
Add two huge base-10 numbers
This is some assembly code I've written to add two base-10 numbers. The input and output are represented as null-terminated ASCII strings, with digits in big-endian order.
I have also provided ...
11
votes
3
answers
2k
views
Remove leading zeroes from the beginning of a string
I want to remove leading zeroes (for a big integer library I'm currently making) in numbers represented as char arrays.
I chose assembly for speed, but in order to simplify making the algorithm and ...
3
votes
1
answer
271
views
Find proceses listening on the network outside of default package manager v2
So this is a follow up questions to Find proceses listening on the network outside of default package manager
I managed to make it a little faster thanks to using ...
4
votes
2
answers
402
views
Find proceses listening on the network outside of default package manager
I have been tinkering with a script that should list things that are listening on the network, but are not part of the base packaging manager. Currently I have only done support for fedora and debian ...
5
votes
1
answer
780
views
Bash script simple countdown timer with dotted output
My goal is to have a timer function that operates from the bash linux command line. I am looking for review and feedback. Printing the expected number of characters (dots, dashes, or bars) is nice-...
2
votes
1
answer
160
views
Iterate over a process' maps file
The following logic provides iteration over /proc/<PID>/maps for a Linux process. What I'm primarily (though not solely) interested in for this review is ...
5
votes
1
answer
481
views
2
votes
1
answer
215
views
Priority Job/Task Queue for Linux (sockets and multithreading)
Preface
Please review my implementation of a job queue for linux/unix systems. This is my first time coding in C, although I have quite some experience in C++.
I know this is a moderate amount of loc, ...
4
votes
1
answer
146
views
Mount point API for Linux systems
I have a use case where I need to check, whether / is mounted read-only.
Here's the module where I implemented this check:
...