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).
562
questions
34
votes
4
answers
20k
views
Recording audio in C
Please note there are newer revisions of this code, one here, and one here for continuous audio recording.
This is a program I wrote as a .wav audio recording library for Linux. It was developed on ...
22
votes
1
answer
820
views
Regular backup/snapshots
A (long) while ago I set up a file server in my basement running Linux. I am OCD when it comes to backups.
I set the server up with (remember, this was a while ago):
disk for OS
disk for 'valuable' ...
20
votes
3
answers
42k
views
Tetris in C, in 200 lines
I aimed at making fully functional (real) Tetris, in the shortest way possible in C. The result is a terminal game for Linux, that uses ncurses. I made it for my friend, who wanted to play it on his ...
18
votes
7
answers
6k
views
Tic-Tac-Toe for the terminal
I recently started learning C, and this is my first fairly large (to me) program. It's a basic Tic Tac Toe game for the console. There's no AI, it's just a 2-player game. Is there anything I can ...
18
votes
3
answers
12k
views
Implementation of the ls command with several options
As part of a past assignment, I've expanded on this implementation of ls to have more options available, including non-standard ones.
It currently supports these (...
18
votes
1
answer
984
views
Calculating the harmonic average
In this program I was required to calculate the Harmonic Average using an assembly program with a C driver.
Harmonic mean is defined as:
$$ \frac{n}{\dfrac{1}{x_1} + \dfrac{1}{x_2} + \cdots + \dfrac{...
17
votes
2
answers
747
views
x64 assembly clearmem / zeromem
I've just started learning assembly yesterday, and the first useful thing I've written is a clearmem function.
I'm looking for general feedback regarding my coding ...
16
votes
2
answers
13k
views
To calculate the total CPU usage as a percentage
I have been developing the below method to calculate the CPU usage of a Linux system at a point in time, as a percentage of the total number of cores available in the system.
...
14
votes
3
answers
14k
views
Parsing ARP cache in C
How can I make this better?
...
14
votes
2
answers
3k
views
malloc() and free() for Linux with system calls
I have written an implementation of malloc() and free() for Linux using the sbrk() system ...
14
votes
1
answer
4k
views
Linux NASM assembly linked list implementation
Inspired by all of the lovely linked lists lately, I decided to implement one in assembly language. This code maintains two linked lists - one is a free store and the other is the active linked list. ...
13
votes
4
answers
1k
views
Light task-processing systems with zero dependency for Linux systems
I made a prototype for a task processing systems.
Architecture
Worker - is a entity that is processing one-by-one tasks for the same processor.
Processor - (also: executable, app) executable file (...
13
votes
3
answers
3k
views
C program for 'Reverse DNS lookup'
I have written the following code for doing a reverse dns lookup. I'm not sure if there are any errors in it. Please have a look:
...
13
votes
2
answers
3k
views
Bash script to automate dev environment setup
After blowing up my environment again messing around with installing random programs and packages I decided to write a bash script I can clone from github and use to reinstall everything like I had ...
12
votes
3
answers
920
views
Iptables Lockdown
I have nginx serving files with uwsgi and I wanted to lock my server down just to allow SSH and Nginx to run.
...
12
votes
4
answers
1k
views
Making kexec reboots less painful
kexec is a way for a Linux kernel to directly boot another Linux kernel without going through the usual BIOS startup sequence, which can take several minutes on enterprise servers. The big problem ...
12
votes
3
answers
2k
views
Bash script that updates Intel e1000e driver
I am now writing a small bash script that updates an Intel NIC driver to the latest version from the official website. Is there any way to improve\simplify the script? I want to avoid a lot of "if......
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 ...
11
votes
3
answers
4k
views
My own little memory manager in C
I have implemented a simple version of malloc() and its associated functions, free(), ...
11
votes
2
answers
520
views
Linux screen dimmer based on battery level
I recently got a new laptop and the battery wasn't the greatest in the world, so I decided on a little project to save some battery:
Make a screen dimmer for Linux distros that use Gnome Shell, ...
11
votes
2
answers
2k
views
Parsing of a (Linux) netlink hotplug uevent packet
The netlink service is used, among other things, to notify userspace about hotplug events (e.g. "a device has been connected"). These events come in the form of packets, which follow the following ...
11
votes
2
answers
1k
views
Implementation of the ls command with several options - follow-up
I've made vast improvements to my previous ls implementation, including:
Added new flags:
-g (omit owner listing)
...
11
votes
1
answer
681
views
Set of wrapper functions for POSIX signal APIs on Linux
Please feel free to comment on the accuracy/validity of the following wrapper source for processing signals using the new POSIX sigaction API. If you feel I'm doing anything wrong or potentially ...
11
votes
1
answer
2k
views
Callback in Linux kernel driver in order to hide device's low-level protocol
I'm am writing a Linux kernel driver for HD44780 LCDs connected via I2C bus. In my last change I tried to decouple low-level code (which talks to the device via I2C) from device's logic (printing ...
10
votes
3
answers
4k
views
Implementation of Linux cp in modern C++
This is my simple implementation of the Unix cp command. It is a C++ program but makes use of some of the lower level C library I/O functions.
Any suggestions for ...
10
votes
5
answers
30k
views
Calculate CPU% by process from /proc/stat and /proc/<pid>/stat
We don't have the possibility to install modules like psutil on some boxes, thus I decided to write a simple script to calculate the CPU percentage by the given PID....
10
votes
2
answers
467
views
Minimalistic rmdir
In my eyes most of the GNU stuff is bloated and doesn't really fit my view of how a Linux environment should look like. I have come up with my own minimalist implementation of the GNU Coreutils, but ...
10
votes
2
answers
1k
views
Wi-fi scheduler written in C
I'm new to C and programming in general (some minimal prior exposure to JS and python). This is also my first time working with shell commands, scripts, and cron. This program works on my macOS and ...
10
votes
1
answer
1k
views
Bash script - automate an upload image + description process on a server
I was tasked at work to improve a system where through a web interface a client, which eventually became us, uploads a bunch of images with descriptions (latter coming from csv files), the images are ...
10
votes
2
answers
266
views
Laptop battery level monitor for Linux
I come from a C background and am trying to learn Rust. I wrote my first Rust program, to check the battery level on my laptop and warn me if it's low/critical.
It works fine, but I wrote it in a ...
10
votes
2
answers
311
views
mini-(Docker)-shell
I was given an assignment to write a mini-shell:
To write your own shell, you will need to start with a C program that
will prompt the user for input and accept in a number of arguments
from a ...
10
votes
2
answers
3k
views
Thread to send heartbeat UDP packets
This C code will run on an embedded machine with a Linux OS. It should create data packets (ASCII) to repeatedly be sent to a UDP server.
Just to give an overview about what functions should do:
<...
10
votes
1
answer
13k
views
Simple Linux upgrade script in Bash
As I will be deploying this script on multiple machines with the very same system Linux Mint 18 with rather same configuration, I would like to be semi-sure I won't screw things up much. This little ...
10
votes
1
answer
196
views
Baby-sitting bash script using DVD drive
This is the script I wrote to make an automated POC baby-sitter in 5 lines.
I first found this on a GIF or meme site and thought of making a POC script that does the same.
...
10
votes
1
answer
221
views
Bash completion functions for pmount and pumount
I found a problem with Debian's Bash-completion for pmount and pumount, and intended to add a patch to the bug report - but I ...
10
votes
1
answer
107
views
Automating a WordPress install
I do not have a whole lot to do over winter break, so I wrote this little script to automate a Wordpress install (currently can only install once instance) on a fresh Debian server (tested, working ...
9
votes
3
answers
2k
views
File Automation Using Python On Linux
A project to automate file organization in Linux using Python. I've always wanted to do this project way before I know how to code. Now that I did, I want to improve it even more.
Used Language: ...
9
votes
2
answers
3k
views
Linux Commands in Python
I've decided to write some Linux commands in Python. Below is a list, along with some constraints (if you're unfamiliar with Linux, the top of the program along has a description about each command ...
9
votes
3
answers
776
views
Daemonizer in C
I am aware that the malloc is a potential memory leak, but with an execvp coming, and that never returning.
The purpose is to ...
9
votes
3
answers
9k
views
Parsing the lsblk output
I am a Python beginner learning Python 3. I have written two small functions that parse the lsblk output and return Linux physical and logical disks. Here is the first function:
...
9
votes
2
answers
675
views
Bash script to truncate subject line of incoming email
I'm going to put this script into production in a mail server /etc/aliases file: we have a system that receives email but the subject line must be limited to a certain size. The proposed usage in the ...
9
votes
3
answers
8k
views
x86 strcpy implementation
I got about 4 days of assembly knowledge, so I need a review on this strcpy function and if it can be done better (at least I have the feeling).
Full code (with ...
9
votes
3
answers
564
views
Can I speed up this simple versioning/backup script?
I'm writing a simple automatic backup/versioning bash script.
It should basically mirror a directory structure somewhere, and then copy files over there when they've been altered. The ghost files ...
9
votes
2
answers
7k
views
Linux backup script in Python
I've written a backup script to make a backup of the latest modified files in 12 hours. Basically, it searches two directories for modified files (statically coded) then the ...
9
votes
2
answers
283
views
Upgrade Firefox Quantum from tarball
I wrote a little script to automate upgrading Firefox to a new version under Debian, since I don't want to install it from unstable and the snap version has ...
9
votes
2
answers
7k
views
Using /proc/stat to calculate CPU usage
Inspired by this question: To calculate the total CPU usage as a percentage
I wrote the following bash script (as an answer) to calculate the CPU usage for a (configurable) period over all CPU cores ...
9
votes
1
answer
5k
views
Basic Linux daemon
I'm looking at writing a simple proxy. At the moment I've got a logger, command line argument parse and simple daemon (it does nothing beyond logging).
Next I'll be looking at starting the network-...
9
votes
2
answers
362
views
Caesar cipher in i686 assembly + MMX
I have written the following implementation of the Caesar cipher for an old Linux computer with a Pentium MMX chip. The code has been written with the following design goals in mind:
the code should ...
9
votes
1
answer
467
views
Systemd service configuration helper script
I've written a script that semi-automates the process of configuring/creating a new systemd service.
The script is working perfectly well, however, I've had some trouble with the styling and ...
8
votes
4
answers
986
views