I am trying to understand the precision of the gettimeofday() system call. Here’s my program: The output if I run this program (./a.out 10) is, The seconds column seems to reconcile with the sleep of 1 secs. Can someone please explain what’s going on with the values in micro seconds column? It looks like the jumps from sleep to sleep
Tag: c++
What does the z component of ncurses mouse events represent?
From ncurses.h What does the z coordinate represent? Answer From the curs_mouse man page: The z member in the event structure is not presently used. It is intended for use with touch screens (which may be pressure- sensitive) or with 3D-mice/trackballs/power gloves. Also, if you search lib_mouse.c in the ncurses source code for ->z and .z, you will find that
Close file in C
Under Linux I use this code to redirect stdout and stderr on a file, as shown in the code the file is opened using fopen(f) and is it closed using close(fd). My question is whether the close(fd) statement closes all file descriptors, or is it necessary to use fclose(f) as well ? Answer The rule is to close the outermost
When reading from /dev/tty, what is happening in input and keyboard buffer?
I am playing with the following two code snippets What the above code wants to do is to read a byte from the user keyboard and then print it to stdout. The confusing thing is two snippets have different behaviors: I am sorry about the format of the above code, I don’t know how to place the prompt at the
When I program in Linux using C, I use the open or creat functions and end up behaving differently
Line 43 is this part of main When I use creat, I get an error line:43 read: Bad file descriptor, but I get the correct result with open. Shouldn’t both functions return file descriptors? Why should creat return the wrong file descriptor When I use creat, I get an error line:43 read: Bad file descriptor, but I get the correct
How do I compile and deliver my application without requiring installation of shared libraries on other machines
On my Ubuntu machine I installed libGLEW. However, I did not install it on my other Ubuntu machine. It works on my compiling machine, but now I received the following error after copying my executable to my other machine. I want to find a solution where I don’t have to require my other machine to install the library. Maybe I
Why am I receiving segmentation fault (core dumped)?
This program was created to log the counter every 5 seconds. The while loop needs to be running while the daemon process is running in the background and logging the counter. The error I’m receiving is: Segmentation fault (core dumped). the terminal ask to input a number, when I input the number I receive the error. I think the while
Is -D_LARGEFILE_SOURCE needed on modern Linux
I’m looking at a very old C based project. It adds the -D_LARGEFILE_SOURCE define when building. Is that preprocessor macro still needed on modern Linux (and if so, why)? Answer I checked the headers. If you are compiling for 64 bit, _LARGEFILE_SOURCE will be defined for you every time. This only does anything for 32 bit. And yes this is
Azure Batch Service: Passing Arguments via Command Line into Application Package on Linux/Ubuntu
Given the following C#/.NET console application running on my Azure Batch Pool/Task: How can I pass the args when adding a command line to my tasks in a Linux/Ubuntu VM. I have tried the following with no success: /bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program -args ‘arg1’ ‘arg2’ /bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program -args ‘arg1’, ‘arg2’ /bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program ‘arg1’ ‘arg2’ /bin/sh -c $AZ_BATCH_APP_PACKAGE_Program_1_0/Program ‘arg1’, ‘arg2’
C program prints to terminal instead of file even after using dup2/dup
I’m in an operating systems course and doing assignments with C on Linux. In one of the assignments I was supposed to redirect and output to a file, but for some reason, I keep getting the output in the terminal instead. I tried writing a simple program to do just that and it still didn’t work: other things I tried