posix

What are the advantages of pwrite and pread over fwrite and fread?

二次信任 提交于 2020-06-09 11:59:06
问题 Hey please don't mind if I am asking trivial question, but, please can somebody help me with this.. 回答1: It's useful when you do a lot of random read/write operations. There is even an option for SQLite3 that replaces seek() + read() and seek() + write() with pread()/pwrite() . The advantage: seek() + read() and seek() + write() both are the pairs of system calls while pread() and pwrite() are single system calls. It's usually an universal truth that the less system calls program issues the

Does OS X support POSIX sessions?

只愿长相守 提交于 2020-05-27 06:42:32
问题 I am working on a project which could make good use of POSIX sessions (as described here) but I'm now uncertain whether I'm misunderstanding the concept and/or whether OS X even supports process sessions. OS X 10.9 has a setsid(2) system call but calling it with arguments 0, 0 seems to do noting. And looking at the output of ps -e -o pid,pgid,sess shows that all processes have a session ID of 0 : PID PGID SESS 1 1 0 11 11 0 12 12 0 13 13 0 14 14 0 15 15 0 16 16 0 17 17 0 [...] Does OS X

UNIX domain datagram - “Invalid argument” on sendto

孤人 提交于 2020-05-17 05:59:07
问题 I am constructing UNIX domain datagram sockets to pass messages from one thread to another thread in the same program. The socket code is written in C and it's called from NASM. Sendto returns (through perror) "socket: Invalid argument." Here is the code for sendto: ssize_t client_send(int64_t sfd, const void * buf, int64_t msgLen, const void * svaddr) { ssize_t result = sendto(sfd, buf, msgLen, 0, (struct sockaddr *) &svaddr, sizeof(struct sockaddr_un)); perror("socket"); if (result !=

shm_open() function no such file or directory

旧城冷巷雨未停 提交于 2020-05-15 05:19:10
问题 I'm trying to create a new shared memory file using shm_open(), but I'm getting errno 2 (No such file or directory). shm_open ("/DIAG_public", O_CREAT | O_RDWR, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH); I've tried creating my own standalone app to run shm_open with the same name and options, and this is successful... So checked that /dev/shm has drwxrwxrwt permissions and that the process running the actual code has -rwxrwxrwx permissions. Also, mount | grep shm returns: tmpfs on /dev

Java线程与Linux内核线程的映射关系

こ雲淡風輕ζ 提交于 2020-04-12 09:26:08
Linux从内核2.6开始使用NPTL (Native POSIX Thread Library)支持,但这时线程本质上还是轻量级进程(LWP)。 Java里的线程是由JVM来管理的,它如何对应到操作系统的线程是由JVM的实现来确定的。Linux 2.6上的HotSpot使用了NPTL机制, JVM线程跟内核轻量级进程有一一对应的关系 。线程的调度完全交给了操作系统内核,当然jvm还保留一些策略足以影响到其内部的线程调度,举个例子,在linux下,只要一个Thread.run就会调用一个fork产生一个线程。 Java线程在Windows及Linux平台上的实现方式,现在看来,是内核线程的实现方式。 这种方式实现的线程,是直接由操作系统内核支持的——由内核完成线程切换,内核通过操纵调度器(Thread Scheduler)实现线程调度,并将线程任务反映到各个处理器上。 内核线程是内核的一个分身。程序一般不直接使用该内核线程,而是使用其高级接口,即轻量级进程(LWP),也即线程。这看起来可能很拗口。看图: (说明:KLT即内核线程Kernel Thread,是“内核分身”。每一个KLT对应到进程P中的某一个轻量级进程LWP(也即线程),期间要经过用户态、内核态的切换,并在Thread Scheduler 下反应到处理器CPU上。) 这种线程实现的方式也有它的缺陷

test for regex in string with a posix shell

纵然是瞬间 提交于 2020-03-18 05:54:25
问题 how can I test if a string matches a particular string matches regex with a basic (no bash or anything) posix shell script (in an if statement)? 回答1: You can use expr command to evaluate regular expression in a POSIX shell: s='Abc' expr $s : '^[[:alpha:]]\+' 3 expr returns # of matched characters which is 3 in this case. 来源: https://stackoverflow.com/questions/35693980/test-for-regex-in-string-with-a-posix-shell

Why was SIGFPE used for integer arithmetic exceptions?

倖福魔咒の 提交于 2020-02-21 10:57:45
问题 Why was SIGFPE used for integer arithmetic exceptions, such as division by zero, instead of creating a separate signal for integer arithmetic exceptions or naming the signal in the first place for arithmetic exceptions generally? 回答1: IEEE Std 1003.1 Standard defines SIGFPE as: Erroneous arithmetic operation. And doesn't really mention floating point operations. Reasoning behind this is not clearly stated, but here's my take on it. x86 FPU can operate on both integer and floating point data

How to properly terminate a thread in a signal handler?

别说谁变了你拦得住时间么 提交于 2020-02-16 03:06:15
问题 I want to set up a signal handler for SIGSEGV, SIGILL and possibly a few other signals that, rather than terminating the whole process, just terminates the offending thread and perhaps sets a flag somewhere so that a monitoring thread can complain and start another thread. I'm not sure there is a safe way to do this. Pthreads seems to provide functions for exiting the current thread, as well as canceling another thread, but these potentially call a bunch of at-exit handlers. Even if they don

How to properly terminate a thread in a signal handler?

我是研究僧i 提交于 2020-02-16 03:04:19
问题 I want to set up a signal handler for SIGSEGV, SIGILL and possibly a few other signals that, rather than terminating the whole process, just terminates the offending thread and perhaps sets a flag somewhere so that a monitoring thread can complain and start another thread. I'm not sure there is a safe way to do this. Pthreads seems to provide functions for exiting the current thread, as well as canceling another thread, but these potentially call a bunch of at-exit handlers. Even if they don

Bad address with mq_open

烂漫一生 提交于 2020-02-06 15:43:12
问题 I am trying to open a simple queue using mq_open but I keep getting error: "Error while opening ... Bad address: Bad address" And I have no idea why. int main(int argc, char **argv) { struct mq_attr attr; //max size of a message attr.mq_msgsize = MSG_SIZE; attr.mq_flags = 0; //maximum of messages on queue attr.mq_maxmsg = 1024 ; dRegister = mq_open("/serverQRegister",O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR,0664, &attr); if(dRegister == -1) { perror("mq_open() failed"); exit(1); } } I updated