What end of the stream does dub2 ( ) change is it the end the OS is connected to or the end connected to application . this code redirect output to file and not the screen which means that input side of stream is connected now to the file right . Answer Before the dup2(), the file descriptor table for
Tag: c++
How to prevent a Linux C++ library from crashing on an out-of-bounds read?
I am using a closed-source 3rd party Linux lib (.so) compiled for an older version of Linux on an older version of gcc. Unfortunately, it crashes occasionally with a read of an invalid memory address. This is certainly undesirable, and it would be fantastic to fix the library. But as that is absolutely impossible, and it still functions perfectly well
Data gets distorted which is printed in loop
Facing issue when printing the data that is updated in malloc. In the below code am creating a string Test.DataType_1.Tag_1 …. Test.DataType_1.Tag_20 in create_tags() function, when the data is updated properly and printed i create_tags() function it prints properly but if printed in main() function in for loop data is distorted. The output of the code is follows, when i
POSIX shared memory model
Is there a memory model specification for POSIX shared memory (across processes)? I’m hoping that there’s something to comparable to the C++ memory model, in order to answer questions like the following: Is there a definition of a data race? Are data races undefined behavior (as in C++)? Is there something to constrain memory visibility order across processes? I know
what is the format specifier for atomic datatype in C++?
I am using Ubuntu virtual box and writing a project in C++. I am unable to put a format specifier for atomic<uint64_t> datatype in C++. Answer Use .load() to get uint64_t out of the atomic, then print it as a regular uint64_t using PRIu64:
Same program/process acquiring lock every time when using LOCK_NB with LOCK_EX flag
I have a requirement, where two separate processes/programs running in parallel (One written in Python and one written in C++) need to get exclusive access, modifying a hardware related value. I’m trying to attain synchronization between them using flock. The code for the same is as below, Python Code C++ Code But, when I run these two programs in parallel,
Communication between two processes without using fork()
I’m trying to do a ping pong exercise, I ask for guidance / direction but not a solution so I can learn. Workspace: ubuntu 19 Language: C. The task is like this: Do not use () fork The ping process is waiting for a signal The Pong process gets the Ping PID from the command line as an argument Pong
I wanted to create a shared memory for student report card data but it returns the error condition in the shmat syscall
I wanted to create a project where the requirement is to use shared memory to create a student report. Asks user for number of students report to be created and dynamically allocate the memory. But when I try to attach it, it gets into the error check if statement and after printing the error message it prints success. } Answer
How to solve pthread_create error (11) resource temporarily unavailable?
I’m building a project in c language (using openwrt as OS) to upload files to FTP server. and i’m using MQTT for the incoming data. So for each topic i subscribe to, i save this data and then upload it to the FTP server and to keep things going smoothly, each time i need to upload a file i just
How to detect when a process is terminated in Linux using C++?
The purpose is I want my program running on Linux to be terminated when some random process is terminated. I can get PID or process handle of the process that my program is to monitor. Are there any possible approaches that I could take? Answer Linux 5.3 introduced pidfd_open, which lets you get a file descriptor from a PID. The