posix

How to execute a command and get output of command within C++?

I am looking for a way to get the output of a command when it is run from within a C++ program. I have looked at using the system() function, but that will just execute a command. Here's an example of what I'm looking for: std::string result = system( "./some_command" ) ; I need to run an arbitrary command and get it's output. I've...

Linux newbie: Linux vs POSIX manual

$ apropos mkfifo mkfifo (1) - make FIFOs (named pipes) mkfifo (1posix) - make FIFO special files mkfifo (3) - make a FIFO special file (a named pipe) mkfifo (3posix) - make a FIFO special file mkfifoat (3) - make a FIFO (named pipe) relative to a directory file ... So I have man pages for Linux Pro...

Equivalent of "pthread_rwlock_timedrdlock()" and "pthread_rwlock_timedwrlock()" in MSVC/Windows

What is the equivalent of following POSIX timed Reader/Writer locks in windows(MSVC)? pthread_rwlock_timedrdlock() pthread_rwlock_timedwrlock() ...

How do I find the current machine's full hostname in C (hostname and domain information)?

In a C project (POSIX), how do I get the fully qualified name for the current system? For example, I can get just the hostname of my machine by doing gethostname() from unistd.h. This might give me machine3 in return, but I'm actually looking for machine3.somedomain.com for example. How do I go about getting this information? I do not ...

How do I read Unicode-16 strings from a file using POSIX methods in Linux?

I have a file containing UNICODE-16 strings that I would like to read into a Linux program. The strings were written raw from Windows' internal WCHAR format. (Does Windows always use UTF-16? e.g. in Japanese versions) I believe that I can read them using raw reads and the converting with wcstombs_l. However, I cannot figure what locale ...

Finding processes using ALSA sound fast

Currently the way /usr/sbin/alsa in Debian knows the processes using the sound card looks like: echo $( \ lsof +D /dev -F rt \ | awk '/^p/ {pid=$1} /^t/ {type=$1} /^r0x(74|e)..$/ && type == "tCHR" {print pid}' \ | cut -c 2- \ | uniq \ ) Which is rather ugly and depends on lsof. I am looking for a POSIX solution without lsof, perha...

C : POSIX threads library test-suite

I'm working on a thread library which implement user level threads (i have something like pthread_setscope which works) and I'm looking for some set of tests to avoid writing one for every function I implement (mutexes, conditions, etc ...) Does anyone know something like that? ...

What does select(2) do if you close(2) a file descriptor in a separate thread?

What is the behavior of the select(2) function when a file descriptor it is watching for reading is closed by another thread? From some cursory testing, it does return right away. I suspect the outcome is either that (a) it still continues to wait for data, but if you actually tried to read from it you'd get EBADF (possibly -- there's ...

pselect() not recognizing the socket having any IO activity

take for instance the following code snippet, the creation of the socket, listening and acceptance of a new socket works fine. The non-blocking mode is also working, however the pselect (or even replacing with select) is not recognizing any IO requests ready on the FDset. so the return value is always 0 (timed out). I was wondering if...

How is an error reported from async socket connect?

I'm connecting a socket asynchronously (O_NONBLOCK + connect). POSIX standard specifies that after socket has been connected is should signal the event by making the file descriptor for the socket ready for writing. It doesn't seem to say anything about failures during async connect. When testing it on Linux, it seems that sometimes I'm...

Posix Threads in c++

How to implement posix threads in linux c++.The smme program when saved as ".c and run using c compiler is ok. but in c++ it is giving error .. I think i made mistake when compiling is there any tag to be included like "-lpthread" for c++ Can someone pls send a valid code...? Actually this is my code int cooperbussman :: startlis...

Are there repercussions to having many processes write to a single reader on a named pipe in posix?

I am writing a program for POSIX (OSX) where I will have many processes sending messages to one listener, who is essentially a logging thread. All of the processes are running in seperate programs, and using a single named pipe (FIFO) that many processes write to, but only a single process reads from is very tempting. Questions: 1) ...

It really looks like OS X has a bug when using poll() on a named pipe (FIFO)... can an expert confirm?

I'm been trying to poll from a set of named-pipes for a little while now and i keep getting an immediate response of POLLNVAL on any named pipe file descriptor. After finding this blog post about broken polling in OS X I'm pretty certain that this is a b-u-g bug in OS X. I'm already planning on switching my code to using UDP sockets, b...

Is fprintf thread-safe?

Is fprintf thread-safe? The glibc manual seems to say it is, but my application, which writes to a file using single call to fprintf() seems to be intermingling partial writes from different processes. edit: To clarify, the program in question is a lighttpd plugin, and the server is running with multiple worker threads. Looking at the...

feeding data to C API expecting a filename

I'm writing a straightforward C program on Linux and wish to use an existing library's API which expects data from a file. I must feed it a file name as a const char*. But i have data, just like content of a file, already sitting in a buffer allocated on the heap. There is plenty of RAM and we want high performance. Wanting to avoid...

pthread callbacks interupt user input

I have written my own stop_watch module. That will create a thread and go to sleep for a period of seconds. Once the seconds have expired it will call a callback function in the main.c and inform the user the time has expired. This is so that the user will only have 3 seconds to enter a digit and they will have to enter 5 digits. If th...

Is there a Java package to read the UNIX /etc/group file?

I have been scouring the Internet looking for a Java package/class that will allow me to parse the UNIX /etc/group file. While it really wouldn't be so hard to write this from scratch, I'm quite surprised not to find something already out there. There is a POSIX passwd class (see http://www.bmsi.com/java/posix/docs/posix.Passwd.html), ...

POSIX Semaphores on Mac OS X: sem_timedwait alternative

I am trying to port a project (from linux) that uses Semaphores to Mac OS X however some of the posix semaphores are not implemented on Mac OS X The one that I hit in this port is sem_timedwait() I don't know much about semaphores but from the man pages sem_wait() seems to be close to sem_timedwait and it is implemented From the man p...

How do I write file modification dates programmatically in POSIX?

Hello. I would like to touch my files from C code to modify their access date. This does not seem to work: struct stat fileSt; lstat(path, &fileSt); fileSt.st_mtime = time(NULL); Thank you for help. ...

Secure and efficient way to modify multiple files on POSIX systems?

I have been following the discussion on the "bug" on EXT4 that causes files to be zeroed in crash if one uses the "create temp file, write temp file, rename temp to target file" process. POSIX says that unless fsync() is called, you cannot be sure the data has been flushed to harddisk. Obviously doing: 0) get the file contents (read it...