posix

Getting the return value of an exec process.

I want the process running to exec. When the command exec runs finishes, I want the process that called the process calling exec to recieve as a return value the value that the function called by exec returned. How is this possible? I'm sorry. I understand the process is a bit confusing. So let me give an example I am in a bash script...

is it possible to use only two semaphores to synchronise three or more threads?

We have three threads or more, can we use only two semaphores (binary or counting semaphores)? An idea that popped into my mind is playing with the number of sem_post-s and sem_wait-s. Any ideas, strategies are welcomed. ...

Problem with gcc tracker/make/fork/exec/wait.

This is a most singular problem, with many interdisciplinary ramifications. It focuses on this piece of code (file name mainpp.c): #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int status; if (fork()) { FILE *f=fopen("/tmp/gcc-trace","a"); fprintf(f,"----------------------------------...

clock_gettime and clock resolution

I'm using the POSIX function clock_gettime on the monotonic clock and the times that I'm getting back aren't multiples of the result of calling clock_getres on the monotonic clock. For example, the resolution is being reported as 0s 999848ns and I have gettime result of 29198s 65414236ns (time divided by resolution gives 29,202,504.19...

Recursive mkdir() system call on Unix

After reading the mkdir(2) man page for the Unix system call with that name, it appears that the call doesn't create intermediate directories in a path, only the last directory in the path. Is there any way (or other function) to create all the directories in the path without resorting to manually parsing my directory string and individu...

What have you used sysv/posix message queues for ?

I've never seen any project or anything utilizing posix or sysv message queues - and being curious, what problems or projects have you guys used them for ? ...

Linking against NPTL for pthread function pthread_condattr_setclock

I've written some pthread code that use timed waits on a condition variable but in order to ensure a relative wait I've set the condvar's clock type to CLOCK_MONOTONIC using pthread_condattr_setclock(). In order to compile and link pthread_condattr_setclock() on RHEL4, i've had to add -I/usr/include/nptl and -L/usr/lib/nptl to my gcc co...

Python: Access Posix' locale database without setlocale()

The setup is a Django based website on an Ubuntu server system with lots of useful information in /usr/share/i18n/locales. The question: Can I access this pool of wisdom without using Python's locale.setlocale() afore? The reason: The docs say, that it is very expensive to call setlocale(), and affects the whole application. But in...

Unexpected result using POSIX ceil() in Perl

I can't for the life of me figure out why the following produces the result it does. use POSIX; my $g = 6.65; my $t = $g * 4; my $r = $t - $g; my $n = $r / $g; my $c = ceil($n); print "$c ($n)\n"; Sigil-tastic, I know — sorry. I've solved this for my app as follows: use POSIX; my $g = 6.65; my $t = $g * 4; my $r = $t - $g; my $n = $...

Get POSIX/Unix time in seconds and nanoseconds in Python?

I've been trying to find a way to get the time since 1970-01-01 00:00:00 UTC in seconds and nanoseconds in python and I cannot find anything that will give me the proper precision. I have tried using time module, but that precision is only to microseconds, so the code I tried was: import time print time.time() which gave me a result ...

What happens when a process is forked?

I've read about fork and from what I understand, the process is cloned but which process? The script itself or the process that launched the script? For example: I'm running rTorrent on my machine and when a torrent completes, I have a script run against it. This script fetches data from the web so it takes a few seconds to complete. D...

Different Linux message queues have the same id?

I open a mesage queue in a .c file, and upon success it says the message queue id is 3. While that program is still running, in another terminal I start another program (of another .c file), that creates a new message queue with a different mqd_t. But its id also appears as 3. Is this a problem? server file goes like this: void server(...

Resources about crash-safe and fault-tolerance programming

I like the LWN article "Crash-only software" and I would like to learn more about crash-safe and fault-tolerant programming. It is surprisingly hard to assure that the persistent state is consistent in fault situations. Here I do not even talk about distributed operations: That is hard on a single node, too: Even the normal Berkeley DB ...

Determining files in a directory

I come from a C# background and I am working on a C++ project. I need to open files in a directory, then process that data in the files. The problem is on my target environment (Greenhills Integrity), I cannot access a "directory". It seems C++ does not have a concept of a directory. Why not? This problem is simple in C#. I cannot ...

Catching signal inside its own handler

#include<stdio.h> #include<signal.h> void handler(int signo) { printf("Into handler\n"); while(1); } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(& act.sa_mask); sigaction(SIGINT, &act, NULL); while(1); return 0; } After catching the KeyboardInterrupt on...

What's the single best reference on the topic of (POSIX) signals?

Signals seem to be one of those areas that should be conceptually simple and easy to explain but I have never come across one source that is both comprehensive, lucidly written, and up to date. In part this seems to be because of historical cruft, lots of exceptions to rules, different programming standards, the confusion threads throw ...

Are there any platforms where using structure copy on an fd_set (for select() or pselect()) causes problems?

The select() and pselect() system calls modify their arguments (the 'fd_set *' arguments), so the input value tells the system which file descriptors to check and the return values tell the programmer which file descriptors are currently usable. If you are going to call them repeatedly for the same set of file descriptors, you need to e...

NFS Client library

Hello. I'm looking for some stand alone library to access NFS shares. I am not looking for mounting the shares, just browsing and accessing the files for reading. Preferable something with a simple simple API similar to regular POSIX operations of opendir, scandir, read and etc. Thanks in advance! ...

Get seconds since epoch in any POSIX compliant shell

I'd like to know if there's a way to get the number of seconds since the UNIX epoch in any POSIX compliant shell, without resorting to non-POSIX languages like perl, or using non-POSIX extensions like GNU awk's strftime function. Here are some solutions I've already ruled out... date +%s // Doesn't work on Solaris I've seen some...

Get directory path by fd

I've run into the need to be able refer to a directory by path given its file descriptor in Linux. The path doesn't have to be canonical, it just has to be functional so that I can pass it to other functions. So, taking the same parameters as passed to a function like fstatat(), I need to be able to call a function like getxattr() which ...