posix

Accessing node data through POSIX tdelete()

The manpage for the POSIX binary tree functions includes the following statements: tdelete() returns a pointer to the parent of the item deleted, or NULL if the item was not found. tdelete() frees the memory required for the node in the tree. The user is responsible for freeing the memory for the corresponding data. ...

How can I get the system language in C/C++?

How can I get the system language in C/C++? Like en_US or en_GB. ...

How to limit the execution time of a function in C/POSIX?

Similar to this question, I'd like to limit the execution time of a function--preferably with microsecond accuracy--in C. I imagine that C++ exceptions could be used to achieve a result similar to this Python solution. Though it's not ideal, such an approach is wholly unavailable in plain C. I wonder, then, how might I interrupt the exe...

Set a timeout for reading stdin

Is there a way to timeout a reading from stdin in order for the program not to hang for too long ? read(0, var, numberofbytes); ...

Sockets and threads using C.

I am new to both sockets and threads. I have this code: listen(socket_fd, 20); /* Looooop */ while (1) { newsocket_fd = accept(socket_fd, (struct sockaddr *) &client_addr, &client_len); if (newsocket_fd < 0) { error("ERROR on accept"); } pthread_t thread; ...

Why do static libraries end in '.a' c++/c ?

Just doing a little work this morning making some static libraries and wanted to know why static libraries end with '.a'. No one in my office knew so I thought I would ask around on SO. We are writing code in C++/C/Obj-C ...

Serial Programming for POSIX, non-standard baud rate

I am implementing a simple program in unix that takes a RS232 input and saves it into a file. I've used these references: http://en.wikibooks.org/wiki/Serial_Programming/Serial_Linux http://www.easysw.com/~mike/serial/serial.html #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <termios.h> #include...

How to execute a process with CAP_SYS_RESOURCE

Hi, im using linux posix mqueue implementation, and i got a bad situation. For current kernel, the max msg size is 1mb. But i need to have no limit. man mq_overview says that if the process is privileged (a process that has CAP_SYS_RESOURCE capability) it has no limits. I thought that a process executed by root was already privileged, bu...

Registering Callback / calling a function when network interface comes up

I want to meassure the time it takes for an interface on a linux system to a) become up and b) become IP capable. This would invoke as a first step to get the linux kernel to tell in some way to call a python function when an 'interface up request' has been sent. Some application (e.g. d-bus) requests: 'iface up' => timer_1.start() ...

What's the Cygwin/Red Hat equivalent to Debian's manpages-dev, manpages-posix-dev?

I'm using Cygwin, and just discovered to my dismay that the package naming scheme is derived from Red Hat. I need the development man pages, called manpages-dev and manpages-posix-dev on Debian-based distros, and can't locate the Cygwin/RH equivalents. What are they? If they're not available, what's the canonical documentation to use in...

What posix_fadvise() args for sequential file write?

I am working on an application which does sequentially write a large file (and does not read at all), and I would like to use posix_fadvise() to optimize the filesystem behavior. The function description in the manpage suggests that the most appropriate strategy would be POSIX_FADV_SEQUENTIAL. However, the Linux implementation descripti...

Getting the current time in milliseconds

How do I get the current time on Linux in milliseconds? This is for the purpose of testing. label1 ..... label2. ...

Does anyone see any problem in this program

After not getting an answer I liked for this question about chroot, I went and rolled my own solution: #include <unistd.h> #include <sys/types.h> #include <pwd.h> #include <stdio.h> extern char **environ; int main(int argc, char** argv, char** envp) { char* path = "/"; char* name = "nobody"; char* exe = "/bin/false"; struct pas...

How do I set the command line arguments in a C program so that it's visible when users type "ps aux" ?

When you type "ps aux" the ps command shows command arguments that the program was run with. Some programs change this as a way of indicating status. I've tried changing argv[] fields and it doesn't seem to work. Is there a standard way to set the command line arguments so that they appear when the user types ps? That is, this doesn't w...

How to durably rename a file in POSIX?

What's the correct way to durably rename a file in a POSIX file system? Specifically wondering about fsyncs on the directories. Note: there are other questions on StackOverflow about durable renames, but AFAICT they don't address fsync-ing the directories (which is what matters to me - I'm not even modifying file data). I currently ha...

Which is better for local IPC, POSIX message queues (mqueues) or Unix domain (local) sockets?

Is it better to use POSIX message queues or Unix domain sockets for local IPC communication? I have worked with Unix sockets between machines (not domain) and I remember that making and breaking the connection would cause sockets to linger awhile before they finally went away. Moreover, if you wanted a "reliable" exchange you either had...

Which Posix socket errors may be recoverable?

Suppose I have established a connection on a socket and got a Posix error code while sending or receiving a packet: one of those listed at the end of this page. On which errors I should not close the socket because trying to send/receive on the same socket again may work? ...

PHP named semaphores?

I've been looking around but I can't seem to find any implementation of POSIX named semaphores for PHP. The only thing I see is SysV semaphores. (2 questions) Is there any way to access named semaphores from PHP currently? Are there any plans for future releases of PHP? ...

IPv4 to decimal different values ?

Why is the IPv4's decimal value different with inet_pton and inet_addr (1734763876) than what you get if you use these 2 websites (1684366951) ? struct sockaddr_in sin; inet_pton(AF_INET, "100.101.102.103", &(sin.sin_addr)); printf("%i\n%i\n", inet_addr("100.101.102.103"), sin.sin_addr); http://www.allredroster.com/iptodec.htm http:/...

UNIX: find a file in directories above $PWD

I want to find a file with a certain name, but search in direcotories above the current one, instead of below. I'd like something similar to: (except functional) $ cd /some/long/path/to/my/dir/ $ find -maxdepth -1 -name 'foo' /some/long/path/to/foo /some/foo Shell scripts or one-liners preferred. In response to the several questi...