In one of my projects I have to cache positional information about certain data chunks found in large files. I’ve already implemented a small API built around std::basic_istream<char>::pos_type placed in maps. Now I need to serialize these descriptors into a bytestream and write them on a disk for…
C: Stop executing and jump to specific point in program on receiving a signal
I have written a code where two independent programs (say 1 & 2) are communicating via message queues. Each programs sends a message of a specific mtype and waits for response of specific mtype. Based on the mtype functions are invoked. program 2 initially waits on select() on the message queue waiting fo…
ansible playbook: check linux process count
I am trying to write a playbook which shows failed when number of process running in linux host is not equal to 2. Following playbook works, but is there any better way of doing it? like is there any specific Ansible module to check process linux host? Answer What is your Ansible version? There is no Ansible …
How to edit a big file
Imagine a huge file that should be edited by my program. In order to increase read time I use mmap() and then only read out the parts I’m viewing. However if I want to add a line in the middle of the file, what’s the best approach for that? Is the only way to add a line and then move
Getting the path to a users documents folder on Linux and MacOSX
I’m currently developing a GUI using Matlab and I need to get the directory of the standard document folder of the user. Under windows I use this: and it works perfectly. Now I planned on doing the same for Linux and Mac with the system(command), but I have no idea what the actual command must look like…
Linux Shutdown and Java Shutdown Hook
When I run a Java process in background and I shut down the computer (ArchLinux), will the computer wait some seconds for the termination of my shutdown-hook in Java? Answer A shutdown hook will be called when a call to close the JVM is made. However, there is no guarantee that the hook will be called. The ho…
What’s the difference between yum -y install and yum install in CentOS
I’ve seen two ways to install packages,for example,squid on CentOS: 1.yum -y install squid 2.yum install squid can anyone tell me what’s the difference between them ? also, I’m using CentOS v.6.6 Answer If you supply -y it automatically chooses “yes” for future questions, i.e. ar…
How to turn off printing result of python “sh” library
I’m working on services with Python, when I try to get status of a service with Python sh library, It will return results in a variable like so: It works fine, but when I try to get status of supervisor service it will print all the results in the terminal and destroys my command outputs. So how to turn…
How to use Linux shell variable with sequence number?
I define several variables like below: And then I want to use them in a for loop like this, but failed. How to make it work? To use the variable with a sequence number. Answer I think you probably need a bash array: Sample Output You should probably avoid uppercase variable names too as they are reserved. If …
How to get stdout/stderr in logfiles immediately?
To run some Python program I use the following bash script: However I can get information after the prog is terminated only. When program is running there are not any data in these files. Can I override this behavior to get log data immediately? My OS is Raspbian. Answer I suspect the program needs to flush s…