Questions tagged [posix]
POSIX (Portable Operating System Interface) is a set of standards defining programming APIs, a command interpreter, and common utilities for Unix-like operating systems.
5,772
questions
-1
votes
2
answers
23
views
sh -c doesn't recognize heredoc syntax
I think the two commands below should be identical, but given the heredoc, the shell produces an error. Is it possible to pass a heredoc to the -c argument of sh?
heredoc example
/bin/sh -c <<...
1
vote
0
answers
22
views
Why does the application have to declare union semun, instead of it being in sys/sem.h?
POSIX says this in the documentation for the semctl function:
type union semun, which the application shall explicitly declare:
union semun {
int val;
struct semid_ds *buf;
unsigned short ...
0
votes
0
answers
18
views
How do I loop over a string's words in POSIX sh (or bash) in linux [duplicate]
I have been trying to find a solution
to how to loop over words in a string
but I am unable to find anything so I
decided to ask here :)
Basically, so far I tried looping over
these ways:
One (not ...
1
vote
0
answers
14
views
What are the semantics of fdatasync() when used on a directory descriptor?
Specifically, can fdatasync be used in place of fsync if I only care about the directory structure and not timestamps or other directory metadata. If it can, does it have any performance advantages?
...
0
votes
1
answer
30
views
Why does user defined signal handler execute again and again when the signal() call resets to SIG_DFL?
Apparently, signal() resets to SIG_DFL (default) which is why another another signal of the same type arriving immediately after the first causes default behaviour to occur. My question is: why does ...
1
vote
1
answer
44
views
testing the program for various memory allocation errors and memory leaks
The tee utility copies its standard input to both stdout and to a file. This allows the user to view the output of a command on the console while writing a log to a file at the same time.
My program ...
-1
votes
2
answers
20
views
How do I combine a Variable with the File Parameter in shell?
.../sh
when I type "$3" I would get the third parameter, but I want to use a variable instead of the static 3. How can I do that?
0
votes
0
answers
17
views
posix regulation does not work with postgreSQL in trigger function
I am working on a trigger function, and I only want to insert the data when it satisfies specific format. So I tried to use posix regulation expressions. But none of it seems working.
if(...
0
votes
0
answers
15
views
App stucks in accept() when LAN interfaces changed
I created a small app on small router with 4 LAN ports. Router has been flashed with OpenWrt system, Linux kernel 5.4.154
Devices connected to LAN ports are sending date over TCP POSTs. The app is ...
1
vote
0
answers
19
views
How to correctly handle a non blocking connection in a multithreaded platform(async poll on SSL_read and SSL_Write) with openssl
Consider the following code:
int SSLWrapper::read() {
while (true) {
int ssl_error = SSL_ERROR_NONE;
{
std::lock_guard<std::mutex> ssl_lock(ssl_mutex_);
if (!ssl_) {
...
1
vote
1
answer
41
views
none IANA time zone - usage still possible?
I need to use time zone strings like this:
CET-1CEST,M3.5.0,M10.5.0/3
CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
But the go time pkg is using the IANA Time Zone database e.g.: Europe/Paris
Is there ...
0
votes
1
answer
37
views
Sending int through shared memory between two processes
I would like to send an int from one process to another through shared memory.
I tried simply placing the value of the int into the shared memory (&number) - didnt work.
I tired casting the string ...
2
votes
1
answer
92
views
Different behaviors between C and Rust code snippets
I have a C code snippet which uses pipe() and fork() to communicate between parent and child process. I want to replicate it in Rust. For the POSIX APIs used in C, if there are counterparts in the ...
-2
votes
1
answer
54
views
Regex - inserting spaces [closed]
i stumbled on a question. The document has values and units like 3m or 3 m. I need to locate the ones without spaces and insert a space using regex. There are many different values and units eg.
5 ...
0
votes
1
answer
50
views
posix_spawn and non-standard pipe setup for ipc between parent and child process
The file actions of posix_spawn describe the setup code for the child process before it might run execve (which deletes stack etc).
The intended use case is to have one or more additional pipes from ...
2
votes
1
answer
189
views
Is there a way to an share address mapping between two unrelated processes on Linux?
I'm assuming if this is possible it would most likely be via mmap
My original question was can mmap() return the same pointer for each user of the same piece of shared memory?
Ultimately an address in ...
1
vote
1
answer
37
views
Number of POSIX queues in the system
I have a strange discrepancy between documentation and reality.
The man 7 mq_overview states:
/proc/sys/fs/mqueue/queues_max
This file can be used to view and change the system-wide ...
0
votes
0
answers
25
views
Can the OS automatically grow an mmap backed file?
mmap has many uses but I primarily use mmap in two ways:
mmap to read an entire file
mmap to create shared memory.
In the case of shared memory if I want it backed by a file I use ftruncate() to ...
-1
votes
0
answers
80
views
What problems exist in the implementation of sleep and how can they be avoided?
I am reading the book APUE and I have reached the following program in the signals chapter:
#include <signal.h>
#include "apue.h"
unsigned int sleep1(unsigned int);
static ...
1
vote
0
answers
30
views
sched_setscheduler always returns EPERM before login
sched_setscheduler always return EPERM(errno 1) before login.
but After login, sched_setscheduler returns OK.
The process of calling sched_setscheduler has the following information.
uid : 0
gid : 0
...
2
votes
0
answers
28
views
Can we poll with keepalive event on a socket fd after the accept?
My main goal is to detect if my client connected to my server is here and responding.
Hence I have developed this server socket (without error handling it is purely experimental):
int opt = 1;
memset(...
2
votes
0
answers
15
views
how to get number of elements of a specific priority in POSIX message queue
I can get the total number of messages in queue with msgctl(int msqid, int cmd, struct msqid_ds *buf) with using IPC_STAT as cmd and the msg_qnum field of msqid_ds struct. Is there a way to know the ...
0
votes
2
answers
40
views
Using C POSIX sockets, can you determine how many bytes a socket contains without extracting?
I'm working with POSIX sockets in C.
Given X, I have a need to verify that the socketfd contains at least X bytes before proceeding to perform an operation with it.
With that being said, I don't want ...
-1
votes
0
answers
24
views
how to get number of elements in POSIX message queue
I have a program where I use APIs like msgget, msgsnd, msgrcv etc. from <sys/msg.h> to create, access, write in, read from message queue. Is there a way to know the number of entries in the ...
1
vote
0
answers
82
views
Is syslog.h still the way to log in modern C++?
syslog.h is the C library to write logs via syslog.
I saw this also in C++ code and wonder, if there is no C++ pendant for this and if it is still good style to include syslog.h in modern C++ projects....
0
votes
0
answers
7
views
Store process specific data by key
I have my own programming language that embeds BoehmGC. Problem is that trouble will start when having multiple instances of boehm loaded in the same process, which is something I want to avoid. When ...
1
vote
0
answers
38
views
How to pass the argument 3 in pthread_create if we have a array and how to become returning values?Prime numbers check
I wanted to know how to get the result like: Number x is prime or Number x is not prime, sure this threaded ex. in 10 parts. How to pass argument 3 if we have an array and how the function checks an ...
-1
votes
0
answers
24
views
shm_ctl() equivalent on Linux?
Link to shm_ctl() manual
This API (which intends to be declared on sys/mman.h) allows any (privileged) user-space process to map a POSIX shared memory (shm_fd) object to specific physical address ...
0
votes
2
answers
40
views
Freeing pointers inside pthread
I want to make a copy of a struct, then pass it into pthread, and finaly free it inside the pthread thread. But i can't fingure this out, it's simply to far beyond me at this point and i can't find ...
0
votes
2
answers
56
views
bash converting lenghty command into lowercase within same line
I have a certain command right now
$(sed $((SS - default_scripts))!d customScripts.txt)
and it gives me Foo Bar, I want to convert this to lowercase but when I tried using the | awk '{print tolower($...
1
vote
0
answers
26
views
Is there a way to prevent sourced scripts in POSIX sh from running anything in global scope?
I'm making a thing which has to source
a POSIX shell script (NOT BASH) as its configuration
file, but it should only have definitions of variables,
functions and comments, nothing else like running ...
-1
votes
2
answers
46
views
What happens if you try to read/write a mapping with a deleted / disconnected backing file or device?
If I perform a mmap() on some file or a device in /dev/ that exposes memory, what happens to that mapping if the file is deleted or that device disconnected?
I've written a test program to experiment ...
0
votes
0
answers
37
views
Permission Denied when trying to use open() with POSIX commands in C++
I currently have this code where I need to use standard POSIX calls to write text to a file:
file = open(filename, O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR);
if (file == -1) {
perror(&...
-1
votes
1
answer
21
views
How to add nullterm to end of mmap() output?
In general, how would I go about adding a nullterm to the end of a mmap() output, so that I can treat it like a string? Before this gets flagged, I do not want to modify the original file. I'm trying ...
0
votes
1
answer
54
views
how to transfer values between threads using I/O streams?
I have a thread that reads data from the console.
I want to write a test on it and the only thing I came up with is to declare another stream that will transmit melons through the I/O streams to the ...
0
votes
0
answers
17
views
How to keep blocking state to read message queue?
The message queue sender is started by a multi-timer. The message queue flag is blocking. I can't use a loop to read messages from the message queue because it takes too much resources. Is there any ...
0
votes
2
answers
22
views
extracting a filepath as a string using a global recursive search?
apologies if this is a basic question, but I couldn't seem to find a clear cut solution. I'm using a global recursive search to find a file with a specific extension in a directory and it's ...
1
vote
1
answer
14
views
output of 'ulimit -c' and posix: whats showing?
I have inherited some scripts where 'ulimit -c ' is set and 'set -o posix' and giving me as a result twice the value or half if I turn it off again.
I see this on "Red Hat Enterprise Linux ...
0
votes
0
answers
42
views
named mmap without Disk IO
I wanted to use the POSIX standard mmap as if shmat had an id, they share the same shared memory.
mmap seems to normally use fd=-1 when using MAP_ANON, and in this case it is said to be valid when ...
0
votes
1
answer
67
views
Looking for ways to 'mock' posix functions in C/C++ code
I am trying to find somewhat elegant ways to mock and stub function calls to the standard C library functions.
While stubbing-off calls to C files of the project is easy by just linking other C files ...
1
vote
1
answer
72
views
SED- Change column from lower to upper case based on 2 conditions from script
I have to change column "name" from lower to upper case based on the condition that the sport column is either shooting or judo.
So far, I have the following code provided by anubhava works ...
0
votes
1
answer
30
views
Handle daylight savings using as.POSIXct() or functions in the lubridate package
Suppose I have given this vector x. I want to convert these to "America/Detroit" time zone.
x <- c("2018-03-10 23:30:00", "2018-03-11 00:00:00", "2018-03-11 00:30:...
0
votes
1
answer
19
views
POSIX multi-value option_argument syntax
I have read https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html.
I understand that a short option_argument can look like -kvalue or -k value.
If we want to specify multiple values ...
0
votes
0
answers
6
views
Passing AD attributes to Realm Joined RHEL 7 box
I have realm joined a rhel7 machine to my Windows AD environment. I was pleased to see that groups were mapped successfully within the rhel7 instance. I was able to see them via the id command.
I have ...
0
votes
2
answers
63
views
How can I make the pthread tasks executes in the correct order according to their priorities?
I'm trying to create 3 thread task with different priorities. The task will only wait or signal other thread tasks, and save the execution in char array to see that they executed as supposed.
Here is ...
0
votes
1
answer
43
views
What's the best way to loop over single line with several separator?
I want to parse the output of fio, I have format them so it has a nice delimiter.
182.07 MB/s|182.55 MB/s|364.62 MB/s|45.5k|45.6k|91.2k#682.65 MB/s|686.24 MB/s|1.36 GB/s|10.7k|10.7k|21.4k#665.21 MB/s|...
0
votes
0
answers
46
views
What are posix/linux/filesystem durability guarantees for ordered file writes?
Suppose I have a (single-threaded) program that (exclusively) opens a large file and does two non-overlapping writes:
int fd = open(path, O_RDWR);
pwrite(fd, data1, size1, offset1);
pwrite(fd, data2, ...
0
votes
1
answer
31
views
Open semaphore without changing its value
Opening a semaphore with sem_open will also initialize it to any given value, is there any way to open a semaphore that is used by another thread without changing its value?
0
votes
1
answer
33
views
Should mqueues be protected by semaphores
Should read mq_receive and write mq_send be protected by semaphores when accessing a queue in a multiprocess program or is there any sort of protection alredy built in
0
votes
0
answers
20
views
Is it possible to control chromium/chrome using pipes?
I'm trying to make an IDE for HTML/CSS/JS and I wanted to add an auto-refresh feature where the user's default browser refreshes the site every time a character is added. I'm new to the idea of pipes ...