ProcessBuilder.start and Runtime.exec seem to use fork() on *NIX system, which seems to allocate the child process the same amount of memory as the parent process (see e.g.
this question ). This can be painful if you want to launch a process which needs almost no memory from a process that uses lots of memory.
Is there any way to laun...
I'm working through a chapter about iPhone audio and have come across a section of code that I can't make sense of:
while (aqc.playPtr < aqc.sampleLen)
{
select(NULL, NULL, NULL, NULL, 1.0);
}
(Full code sample is on pages 163-166). From what I understand of the code the audio is being processed on another thread and the while lo...
Why does this work :
char *fd = "myfile.txt";
struct stat buf;
stat(fd, &buf);
int size = buf.st_size;
printf("%d",size);
But this does not work:
char *fd = "myfile.txt";
struct stat *buf;
stat(fd, buf);
int size = buf->st_size;
printf("%d",size);
...
I have a FILE *, returned by a call to fopen(). I need to get a file descriptor from it, to make calls like fsync(fd) on it. What's the function to get a file descriptor from a file pointer?
...
I have the following code. It gives me a problem with free memory, but I haven't figured out what exactly the problem is. It seems that getpwuid(buf->st_uid); is not getting along with readdir(dirh); or with stat functions. Does anyone know why?
buf = (struct stat*) malloc(sizeof(struct stat));
for (dirp[i] = readdir(dirh); dirp...
This following is a straightforward IPv4 UDP broadcast, followed by listening on all interfaces.
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
sock.bind(("", 1337))
sock.sendto("hello world", ("255.255.255.255", 1337))
while True:
data, addr = sock.recvfrom(0x10...
I'm working on a TFTP implementation that is transitioning away from a convoluted multi-threaded implementation to a single-thread/single-process implementation which uses a state machine to track the state of the sessions connected. TFTP is simple enough, and the number of concurrent sessions are small enough that the there really is no...
Is their any C popen() equivalent in C++ to ?
...
Mmap returns a void*, but not a volatile void*. If I'm using mmap to map shared memory, then another process could be writing to that memory, which means two subsequent reads from the same memory location can yield different values -- the exact situation volatile is meant for. So why doesn't it return a volatile void*?
My best guess is ...
I know how to remove files in order to make them impossible to recover. But, how do I remove rows from a MySQL table in a POSIX environment in a way that leads to the same results? I'm currently rewriting all data with a nullified string with the same length as the original data before I proceed with deleting the row. Does it work? If no...
Is there any portable way (on POSIX systems) to determine if a file descriptor is seekable? My thought is to use lseek(fd, 0, SEEK_CUR); and check if the return value is -1, but I'm uncertain if this could give false negatives or false positives. Using fstat and making assumptions about what types of files are seekable/nonseekable does n...
I'm using a Java wrapper for a native shared library on Unix (JRI). The native library (a C based REPL implementation for R) handles SIGINT internally. When using the Java wrapper, the Java application quits when I send a SIGINT to the process using:
kill -SIGINT pid
I'd prefer for the SIGINT to be entirely handled by the native libr...
In a POSIX environment, I want to remove a file from disk, but calculate its checksum before removing it, to make sure it was not changed. Is locking enough? Should I open it, unlink, calculate checksum, and then close it (so the OS can remove its inode)? Is there any way to ensure no other process has an open file descriptor on the file...
I've been having some trouble with FreeBSD and large mmaps. Linux does not show the same problems.
On program startup it can always get the 1 GB map. However, there's a reload operation where the file is replaced and remapped. The new map is usually just a little bigger each time so it doesn't fit neatly into the old mmap location. This...
In limits.h, and in various places in the POSIX manpages, there are references to PATH_MAX and NAME_MAX.
How do these relate to one another?
Where is the official documentation for them?
How can I obtain them at run time, and (where relevant) compile time for the C, Python, and GNU (shell) environments?
...
I'm presently writing a filesystem. The statvfs (and even the statfs) structs contain a field specifying the maximum length of a name in that path. As PATH_MAX is defined in the pathconf manpage (getconf), this means it is defined on a per-directory basis (and thus, determined by the underlying filesystem). How does one specify this valu...
Is there any implementation of scanf()(like in C) in awk(POSIX)?
I know that awk does not have back reference like in sed and perl.
What is the easiest way to simulate in awk?
Thanks
Nyan
...
Is there a way to find out the default language of a Linux system from C? Is there a POSIX API for this? E.g. I'd like to have a string in human readable format, i.e. "German" or "Deutsch" on a German system, "French" or "Francais" on a French system etc. Is there something like this?
Thanks!
...
A couple of days ago I had to investigate a problem where my application was showing abnormally high CPU usage when it was (apparently) in idle state. I tracked the problem down to a loop which was meant to block on a recvfrom call while the socket had been set to O_NONBLOCK-ing resulting in a spin lock. There were two ways of solving th...
I've just discovered that the stat() call, and the corresponding struct stat, does not contain fields for the file times with precision greater than one second. For setting these times, there are a variety of {f,l}utime{n,}s() functions, but not for getting.
How then does obtain these times with nanosecond precision, preferably using PO...