posix

POSIX named pipe (fifo) drops record in nonblocking mode

那年仲夏 提交于 2021-01-28 12:00:37
问题 I am using POSIX named pipes (fifos) to send records from one or more threads to be read by another thread (only one thread does the reading). However, the 83rd record out of 100 records is simply dropped. The client core calls write and the return value is correctly reported as the length of the record (720 bytes) so the client (writer) core confirms that the record is sent, but switching to the reader core in gdb debug mode with scheduler-locking on, I cycle through reading the few previous

_POSIX_* (limits.h) vs _SC_* (sysconf)

佐手、 提交于 2021-01-28 11:34:09
问题 I just noticed the macros named "_POSIX_*" in limits.h are (namewise) similar to the parameter of sysconf function . For example, there is the macro named "_POSIX_ARG_MAX", and I can also call sysconf with the argument of "_SC_ARG_MAX". Why do we need sysconf in the first place when we're totally free to use the macros in limits.h? 回答1: The _POSIX_* values are the minimum requirement to be POSIX compliant. They will have the same value on all platforms. The particular value supported by the

Writing data read with read () to int array in C

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-28 11:33:46
问题 I have a file with numbers on each line. I am trying to write the data read from the file to the int array with the read () function. I can read the file and print it to the terminal. How can i get the numbers i read into arr array ? Here is my code #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> int main() { int len, fd,arr[10000],i=0; fd = open("1.txt", O_RDONLY); if (fd >= 0) { while(read(fd, &len, sizeof(int)) > 0){ write(1, &len, sizeof

How to circumvent dlopen() caching?

…衆ロ難τιáo~ 提交于 2021-01-28 06:08:27
问题 According to its man page, dlopen() will not load the same library twice: If the same shared object is loaded again with dlopen(), the same object handle is returned. The dynamic linker maintains reference counts for object handles, so a dynamically loaded shared object is not deallocated until dlclose() has been called on it as many times as dlopen() has succeeded on it. Any initialization returns (see below) are called just once. However, a subsequent dlopen() call that loads the same

Why I can create a shared memory bigger than the size mounted on /dev/shm using POSIX?

久未见 提交于 2021-01-28 05:46:58
问题 I am trying to handle errors using shared memory IPC in a Ubuntu 16.04. First, I checked the available memory in /dev/shm using df -h, having 500M availables, so I coded something quickly in order to check what happens if I try to create a shared mem bigger than the mounted size. The code is the following (it has been modified several times so I know that is not very tidy): #include <iostream> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ipc.h> #include <sys

Why does POSIX demand that system(3) ignores SIGINT and SIGQUIT?

那年仲夏 提交于 2021-01-28 05:07:24
问题 The POSIX spec says The system() function shall ignore the SIGINT and SIGQUIT signals, and shall block the SIGCHLD signal, while waiting for the command to terminate. If this might cause the application to miss a signal that would have killed it, then the application should examine the return value from system() and take whatever action is appropriate to the application if the command terminated due to receipt of a signal. This means that a program that starts a long-running sub-process will

Read string from shared memory C++ POSIX

偶尔善良 提交于 2021-01-28 05:05:20
问题 In my other question one user help me with send string by shared memory. But when I try to receive this data program says Core dumped . I try this code: key_t lineKey = ftok("/tmp", '1'); int sharedLine = shmget(lineKey, sizeof(std::string), IPC_CREAT | 0666); std::string *line = (std::string *)shmat(sharedLine, NULL, 0); sem_t *reader1_sem; reader1_sem = sem_open("reader1_sem", O_CREAT, 0666, 0); while (1) { sem_wait(reader1_sem); std::cout << (*line); } I tried also rewrite this to char *

Are there in AIX mechanisms EPOLL/KQUEUE or their equivalents?

[亡魂溺海] 提交于 2021-01-28 00:34:55
问题 Are there in AIX mechanisms EPOLL(Linux2.6)/KQUEUE(FreeBSD)/IO Completion Port(Windows) or their equivalents? And what kind of mechanisms are optimal for AIO on AIX for a large number of network connections? For example according to the Benchmarks, the mechanisms KQUEUE / EPOLL much faster than SELECT. http://libevent.org/ 回答1: I believe poll set is the best choice today. There is also the iocp interfaces which comes from windows. And there are the aio interfaces which use iocp under the

Changing syslog log path

独自空忆成欢 提交于 2021-01-27 23:30:43
问题 How do I change the log path of syslog daemon during runtime? My goal is to rotate log file every filesize or date, but I don't have logrotate in QNX/POSIX. Do I just do an edit and hope that the syslogd checks the .conf file everytime, or is there any other workaround? Thanks. Clarification: It has to be done in C or C++, not in script and console command line, for portabality issues. 回答1: Find the pid of syslogd. Let's say it's 123. Then, after you've finished your edit, on the command line

Can I get the access mode of a `FILE*`?

亡梦爱人 提交于 2021-01-27 04:39:15
问题 I have to duplicate a FILE* in C on Mac OS X (using POSIX int file descriptors all the way is unfortunately out of question), so I came up with the following function: static FILE* fdup(FILE* fp, const char* mode) { int fd = fileno(fp); int duplicated = dup(fd); return fdopen(duplicated, mode); } It works very well, except it has that small ugly part where I ask for the file mode again, because fdopen apparently can't determine it itself. This issue isn't critical, since basically, I'm just