Questions tagged [posix]

POSIX is an acronym for Portable Operating System Interface, a set of standards defining programming APIs and utility behavior for Unix-like operating systems.

Filter by
Sorted by
Tagged with
5 votes
1 answer
85 views

Executing a Bash script from C++

I am trying to execute a Bash command, get the pid, read the (error) output and optionally pass input. I am still quite new at C++ and I would like to know if this is a correct & safe ...
2 votes
1 answer
52 views

System V signal API using the standard POSIX API

I wrote a program that implements a POSIX signal API. It implements the functions sigset(), sighold(), ...
  • 21
4 votes
1 answer
63 views

improved "tee" utility

We have modified the tee program with your suggestions from the previous pull request. Did I implement well? I would like to optimize the program even more, what ...
  • 199
3 votes
2 answers
468 views

Implementation of the "tee" utility program

How can I optimize the program? To make it more optimal? The program should be more optimal in terms of source code, compiled executable size, memory usage, speed, bugs etc. Please criticize the ...
  • 199
3 votes
3 answers
103 views

tee: copy standard input to both stdout and a file

I implemented the tee command from linux. The program also handles the -a option for adding text to the end of a file if it ...
  • 199
5 votes
0 answers
131 views

A POSIX getdelim() and getline() implementation for MSVC

Tired of always having problems in reading arbitrary length lines from file under Windows, I tried to write a POSIX getdelim() and ...
3 votes
2 answers
67 views

change file attributes on a Linux file system with chattr

I am reading the book The Linux Programming Interface and I have reached the exercise in which the implementation of the chattr command in C is required. I would ...
  • 51
15 votes
2 answers
1k views

A multithreaded implementation of the 'which' command

Here is an implementation of the 'which' command which can tell where programs are located. ...
  • 161
1 vote
2 answers
105 views

Function that behaves as dup2

I am reading the book Advanced Programming in the UNIX Environment and I have tried to solve the following exercise: Write a function that performs the same actions as ...
  • 449
3 votes
2 answers
130 views

Retry read/write until all bytes are transferred or error occurs

Currently I have a wrapper function for the read/write system calls, the purpose of which is to eliminate partial transfer ...
's user avatar
4 votes
1 answer
53 views

Whose `git` is it anyway?

A Posix function for finding the nearest parent file. For example "what .git/ am I working in?" or "is there an .npmrc affecting npm from this path?&...
  • 882
1 vote
2 answers
72 views

Editing system files in Linux (as root) with GUI and CLI text editors #3

One year and a half ago I posted the second iteration of this script for a review here: Editing system files in Linux (as root) with GUI and CLI text editors #2 Since then, it has been "...
3 votes
1 answer
80 views

UNIX calendar(1) in C

This is a simple implementation of the calendar(1) utility included in some UNIX systems (all BSDs have it, GNU has not). I do not have much experience with ...
  • 854
3 votes
2 answers
88 views

Posix signal implementation

My hobby is Unix-like operating systems. Recently I began writing my own sel4-based Posix compliant OS. Here's the code for internal signal handling functions which presents a kind of backend to help ...
1 vote
2 answers
84 views

Installing packages if they don't exist in Bash

This script simply installs the chosen packages if they're not present on a Linux system using the apt package manager. Notes on improvements of any aspect are ...
  • 2,927
6 votes
3 answers
705 views

Updating text in a HTML document with Bash

This is a small script to update my project's README file. Notes on improvements from any aspect are welcome! Here is the document it updates. readme.sh (Executed like so: ./readme.sh) ...
  • 2,927
3 votes
0 answers
65 views

The Blacklist v2

This script gathers domains listed from sources in this JSON file and compiles them into one text file. Text files that have a similar key under the whitelists ...
  • 2,927
3 votes
1 answer
128 views

Pomodoro timer daemon in C for BSD systems

I wrote a Pomodoro timer daemon for BSD systems in C (may work on Linux with -lbsd). The server uses poll(2) and sockets to communicate with the client and to ...
  • 854
3 votes
3 answers
346 views

Efficiently read a file into a (C) string using POSIX APIs

Exactly what the title says, this is a C++ class that attempts to read a file into a null-terminated string as efficiently as possible, using POSIX APIs. Obviously this is not intended to be portable ...
  • 258
4 votes
1 answer
116 views

Recursively list directories

How does the following look to list the directories on a posix system? This is actually the first piece of C code that I've written where I've actually been able to use for a real-world problem! ...
  • 333
4 votes
2 answers
461 views

C++ TcpServer class

I have a class Tcp_Server that implements a TCP server. This is the base class for the other types of servers available in my program. For example ...
  • 135
0 votes
1 answer
54 views

Attempt on basic input validation and functional programming in a POSIX shell

In spite of all the POSIX shell disadvantages, I am still sticking with it and I love its portability. Recently, I was searching for a way of code re-use, which turns out to be structured programming ...
5 votes
2 answers
142 views

Log file name adjustment

I have the following code that takes user input "path" and adds the current time into the filename after the name part and before any extension (if it exists). It seems a little hacky to me ...
3 votes
1 answer
82 views

*nix, *bsd, etc basic `tput` color setup

My goal with the below piece of POSIX shell code was to address the more platforms the better with shell tput colors. With this code, I now start all of my scripts, ...
1 vote
2 answers
1k views

Regex to match each line in a file, with windows and/or linux line break included, even for missing line break at EOF

My requirement is to match each line of a text file, including the line terminator of each, at most excluding the terminator of the last line, to take into account the crippled, non POSIX-compiant ...
  • 507
1 vote
0 answers
29 views

Implementation of GNU shuf(1) now supporting nul characters

Some time ago, I implemented shuf(1), but it had an issue: it ignored nul characters in the input. This new version tries to solve this problem (but uses the ...
  • 854
3 votes
1 answer
102 views

POSIX + BSD-extensions implementation of shuf(1)

I implemented GNU shuf(1) in C using POSIX system calls and some BSD extensions. You must compile it with -lbsd. ...
  • 854
1 vote
0 answers
42 views

sudoedit_enhanced written POSIX-ly (readlink possible problem?)

sudoedit_enhanced written POSIX-ly challenge While creating sudoedit_enhanced POSIX (apart from ...
2 votes
1 answer
216 views

POSIX shell function to "dump" all given arguments

My today's idea was to create a POSIX shell function to dump all given arguments, typical use would be to call it from a fucntion, where you already know some arguments are not well set (empty; not ...
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 (...
  • 273
1 vote
2 answers
130 views

Editing system files in Linux (as root) with GUI and CLI text editors #2

This is the second iteration of this question A note to start with: the first iteration of this question can be found here: Editing system files in Linux (as root) with GUI and CLI text editors As ...
0 votes
3 answers
111 views

Safer & simpler allocation functions and macros

I wrote a bunch of functions and macros for safer and simpler allocation. They are documented in their files. Disclaimer: The library requires POSIX extensions, GCC extensions, and LIBBSD ...
  • 1,868
4 votes
2 answers
118 views

Generic circular doubly-linked list v2

I've improved, with help of the answers and comments, the linked list that I posted yesterday. It's been through a lot of changes, and is much more useful and safe now. I documented the linked list ...
  • 1,868
2 votes
0 answers
37 views

Bash script to scp specific, most-recent files from remote server

I'm writing a helper script that I wish to be able to share with my co-workers. We all work using macOS Mojave, but all have their own shell configurations. For example, I actually use ZSH and bash 5....
  • 225
12 votes
3 answers
2k views

Correctly applying the "rule of five" to a RAII socket wrapper

I was trying to create a simple RAII wrapper with rule of 5 for a TCP POSIX socket. My aim was to try learn how to apply rule of five in different situations, but this one was somehow tricky. ...
  • 285
6 votes
1 answer
78 views

POSIX+ implementations of echo(1)

Ever wanted a strictly conformant echo(1) implementation on your system? Wait no more: I've built it! What is it? My first large-ish body of C code in a while. ...
8 votes
1 answer
379 views

Console arkanoid in C

On an Internet forum a person came with their homework, to write Arkanoid in a console - it seemed they wanted someone to do their homework for them so I did not respond. However, I found the task ...
  • 571
9 votes
1 answer
579 views

Custom malloc implementation

I have a malloc() implementation that relies purely on mmap. I'm fairly sure that it doesn't overwrite any of the internal ...
  • 1,704
1 vote
1 answer
115 views

Bash Code to backup the history file in Linux [closed]

How is the logic, efficiency and can it be improved? This is a snippet from my .bashrc file, I just wrote it. The code is supposed to do this: Backup my ...
3 votes
2 answers
172 views

POSIX shell function for asking questions

I've written a tiny function for asking questions intended for my POSIX shell scripts, where I often need user input. The function takes 2+ arguments, where: Is a string containing the question. , 3....
3 votes
1 answer
105 views

batch add users to nextcloud on docker with csv

I have a working script that will batch add users to an instance of nextcloud running on top of docker. This version is the result of changes made after asking this question. I guess I'm looking for ...
  • 183
2 votes
1 answer
107 views

Editing system files in Linux (as root) with GUI and CLI text editors

My intention is to POSIX-ly write one generalized function for running various text editors I use for different purposes through sudoedit, i.e. editing files as ...
3 votes
1 answer
28 views

Is device mounted? Both UUID and device names accepted

I am trying to write is_device_mounted script, which in turn will serve a greater purpose in my home Linux system. It does not even have an error reporting ...
2 votes
1 answer
342 views

C Recursive Opendir Wrapper to Sort Directories First (ascending/descending)

A recent post on StackOverflow about a recursive directory listing which produced an unsorted mixed file/directory list, sparked the stray thought of "What would it take to write a wrapper for the ...
2 votes
2 answers
81 views

Lock file and interrupt signals in POSIX shell script running indefinitely

This script is running indefinitely as the Linux background process. I have put an enormous effort to make this POSIX shell script containing an infinite loop shut down tidily along with the ...
2 votes
2 answers
45 views

POSIX-ly finding a specific Java process

In this code I find a list all of the running java processes and give the below function a name to look for, it will do its best. But since I find my approach a ...
3 votes
1 answer
94 views

Easy to use code preparation script for CodeReview questions

We all face questions that forget to include their code. Sometimes all of it, sometimes only parts, that make the rest of the question unfortunately incomplete and therefore off-topic. What if it was ...
  • 18.9k
1 vote
1 answer
261 views

Detecting the total amount of RAM installed on a hardware from a Linux system using a POSIX shell script

Today, I gave myself a small task of detecting the total amount of RAM installed on a hardware from a Linux system using a POSIX shell script. I ended up using ...
0 votes
1 answer
45 views

Shell POSIX OpenSSL file decryption script follow-up #3 (final)

From original very simplistic code: Shell POSIX OpenSSL file decryption script I learned a lot both from the first follow-up review, and the second one as well, many thanks! I just need one final ...
0 votes
1 answer
59 views

Shell POSIX OpenSSL file decryption script follow-up #2

This question is the second follow-up of: Shell POSIX OpenSSL file decryption script The first follow-up was: Shell POSIX OpenSSL file decryption script follow-up #1 Both of which have proven very ...