posix

Setting windows creation date using POSIX api

I have a program (jhead) that compiles with very few tweaks for both Windows and generic Unix variants. From time to time, windows users ask if it can be modified to also set the "creation date/time" of the files, but I don't see a way to do this with the POSIX api. What I'm currently doing is: {     struct utimbuf mtime;     mtime....

C++/POSIX how to get a millisecond time-stamp the most efficient way?

Hi, I'm using a open-source library for i2c bus actions. This library frequently uses a function to obtain an actual time-stamp with millisecond resolution. Example Call: nowtime = timer_nowtime(); while ((i2c_CheckBit(dev) == true) && ((timer_nowtime() - nowtime) < I2C_TIMEOUT)); The application using this i2c library uses a lot o...

Using threads, how should I deal with something which ideally should happen in sequential order?

I have an image generator which would benefit from running in threads. I am intending to use POSIX threads, and have written some mock up code based on https://computing.llnl.gov/tutorials/pthreads/#ConVarSignal to test things out. In the intended program, when the GUI is in use, I want the generated lines to appear from the top to the ...

Configure Visual Studio 2008 to compile Posix applications

Hello, I'm an experienced programmer in .Net languages but I have not almost any work experience in C++ or C development. I currently have to develop an application for a device running VxWorks (a realtime OS). We will first build a x86 version and then port to VxWorks. As VxWorks is Posix compliant we plan to create a Posix applicatio...

lseek() returning 0 when followed by new open()

I have the following bit of code (it's "example" code, so nothing fancy): #include <stdio.h> #include <string.h> #include <fcntl.h> #include <sys/types.h> #include <unistd.h> int main() { char buffer[9]; int fp = open("test.txt", O_RDONLY); if (fp != -1) // If file opened successfully { off_t offset = lseek(fp,...

If 256 threads give better performance than 8 have I likely got the wrong approach?

I've just started programming with POSIX threads on dual-core x86_64 Linux system. It seems that 256 threads is about the optimum for performance with the way I've done it. I'm wondering how this could be? And if it could mean that my approach is wrong and a better approach would require far fewer threads and be just as fast or faster? ...

Are open streams automatically flushed and closed on SIGINT in C?

I've read in a man page that when exit() is called all streams are flushed and closed automatically. At first I was skeptical as to how this was done and whether it is truly reliable but seeing as I can't find out any more I'm going to accept that it just works — we'll see if anything blows up. Anyway, if this stream closing behavior is ...

Number of inodes in a partition not matching up to the maximum number of inodes the partition should support

We are using Amazon EBS to store a large number of small files (<10KB) in a 3-level directory structure. ~/lists# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 9.9G 3.9G 5.5G 42% / tmpfs 854M 0 854M 0% /lib/init/rw varrun 854M 64K 854M 1% /var/run varlo...

In a POSIX environment, how do I track files accessed by a child process?

I have my own POSIX application which starts a child process. I want the parent process to be notified with the names of all files the child process reads or writes, as well as the file names of any child processes the child spawns, and any dynamic libraries it loads. Similarly, I need to monitor all child processes spawned by child proc...

Write my own 'everything is a file' interface

I would like to expose the settings and statistics of my program in a 'everything is a file' manner - sort of how /proc/ and /sys/ works. As an example, imagine for a moment that apache2 had this type of interface. You would then be able to do something like this (hypothetical): cd /apache2/virtual_hosts mkdir 172.20.30.50 cd 172.20.3...

What more socket APIs are available? What are the differences between each of these Socket API?

Everyone referred to it as Socket Programming or Network Programming in C and we started using it by using by including sys/socket.h & netinet/in.h. We thought it was 100% true. But question raised in my mind when I saw this book Internetworking With TCP/IP Volume III: Client-Server Programming and Applications, which was available in 4...

safe way to use dprintf

Linux has this nice function dprintf: The functions dprintf() and vdprintf() (as found in the glibc2 library) are exact analogues of fprintf() and vfprintf(), except that they output to a file descriptor fd instead of to a given stream. however as that same source points out: These functions are GNU extensions, not in C or POS...

Why POSIX is called "Portable Operating System Interface"?

I have searched hard but still confused why POSIX is called "Portable Operating System Interface", what I learned is that it is some threading library for Unix environment, because when you need to use it under windows you have to use cygwin or "Windows Services of Unix", etc. That's why I am confused why it is called Portable OSIX. I a...

pthread_exit() and initial thread

When I use pthread_exit() in the initial thread, the initial thread switches in the terminated state. But I did not understand about the process. Can exist a running process with the initial thread in the termitated state? ...

recv() with errno=107:(transport endpoint connected)

well..I use a typical model of epoll+multithread to handle massive sockets, that is, I have a thread called epollWorkThread that use epoll_wait to handle i/o sockets. While there's an event of EPOLLIN, recv() will do the work and I do use the noblocking mode to allow immediate return. And recv() is indeed in a while(true) loop. Everythin...

Are BSD/Posix sockets reentrant?

Can several threads operate on the same socket descriptor, i.e accept(sock_fd) at the same time without concern? The platform I'm mostly interested in is POSIX/Linux. ...

About POSIX naming convention

I am learning posix api. I could not get logic behind names used by posix api e.g. S_IRUSR, S_IRUSR What does What does S stand for? I can get R and W are for read and write. But what naming convention followed by POSIX ? Its just an example. What about other names ? Just like Win32 follow Hungarian Notation for naming what does P...

Run linux command line commands from Qt4

...and of course obtaining the output in some way I can use it. I'd use it for an ls | grep, but it's good to know for any future issues. Thanks in advance. ...

revisiting "how do you use aio and epoll together"

following the discussion at http://stackoverflow.com/questions/1825621/how-do-you-use-aio-and-epoll-together-in-a-single-event-loop. There are in fact 2 "aio" APIs in linux. There's POSIX aio (the aio_* family of functions), included in glibc and libaio developed I believe by RedHat (?), the io_* family. The first one allows registrat...

Is a return value of 0 from write(2) in C an error?

In the man page for the system call write(2) - ssize_t write(int fd, const void *buf, size_t count); it says the following: Return Value On success, the number of bytes written are returned (zero indicates nothing was written). On error, -1 is returned, and errno is set appropriately. If count is zero and the file ...