I want to write a program to get integers from a file and put them in a buffer using multiple threads. The buffer size is 20 and there are 100 integers. I can’t use for-loop because one thread should read one integer at a time. As an example, if we are using one thread that thread must run 100 times
Tag: posix
How to dynamically check for library information in posix compliant systems in C++?
I am playing around with Linux to learn some things about operating systems. Currently I want to query the OS for the version of certain libraries (GLFW and GLEW on particular). I want to print the current version or a message if the library is not installed. Is there a general way to query the OS for the version of
How to find which process owns the named posix semaphore lock? [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 4 years ago. Improve this question I used named semaphore to synchronize multiple processes in my system. One of
New to bash scripting – want to have a code block execute many times via reference
I am totally new to bash scripting. I am wondering if there’s a way that I can create a reference for the following code block: Is there a way I can give this block of code a reference point and execute it using the reference several times throughout the rest of the script? Would it be easier/better to create a
What type of memory objects does `shm_open` use?
Usually, shared memory is implemented using portions of On-Disk files mapped to processes address spaces. Whenever a memory access occurs on the shared region, the filesystem is involved to write changes on the disk which is a great overhead. Typically, a call to fopen() returns a file descriptor which is passed to mmap() to create the file’s memory map. shm_open,
How to ensure a posix c socket is still valid
I,m working on an embedded linux kernel 2.6 device and need to know if previously established socket is still valid or not,Also I can not do this with usual send function and check the returned value,because if I send to the invalid socket descriptor,my application will crash and linux will shut down my process.Is there any other function/suggestion for this
pthread_kill() not sending signal to main thread (main program)
signal can be received in any threads or main program itself. i have created one auxiliary thread from main program. so there is two thread in my program 1. main thread (process itself) 2. Auxiliary Thread. I just want that whenever signal arrived in my auxiliary thread, that should send signal to my main thread (program). i am using pthread_kill(main_threadid,
Why sem_t pointer have to start at multiple of 4 offset?
When you accessing block of memory (f.e. in real case using mmap) correct pointer for sem_t have to by multiple of 4. If it is not, then sem_init() still doesn’t return -1 (error value), but sem_t isn’t valid. Why it is working like this? Below code that is showing behaviour of semaphores. Answer ALL1 types in C may have alignment
Trimming string up to certain characters in Bash
I’m trying to make a bash script that will tell me the latest stable version of the Linux kernel. The problem is that, while I can remove everything after certain characters, I don’t seem to be able to delete everything prior to certain characters. Somehow the output “ignores” the wget=${wget##.tar.xz”>} line. Answer You’re trying remove the longest match of the
Why makecontext’s func only accepts integer arguments
The man page for makecontext states that the arguments after argc should be integer(int) only: …the function func is called, and passed the series of integer (int) arguments that follow argc If we look at pthread_create or clone system call, they have one void* argument which is to passed to the func, and a pointer of struct can contain any