posix

How can I tell whether SIGILL originated from an illegal instruction or from kill -ILL?

半世苍凉 提交于 2019-12-23 21:27:59
问题 In a signal handler installed through void (*sa_sigaction)(int, siginfo_t *, void *); , how can I tell whether a SIGILL originated from an illegal instruction or from some process having sent SIGILL? I looked at si_pid of siginfo_t, but this seems to be uninitialized in case an illegal instruction was encountered, so that I can't base my decision on it. - Of course, I'm searching for a preferably simple and portable solution, rather than reading the instruction code at si_addr and trying to

How to share existing char * with an other process?

走远了吗. 提交于 2019-12-23 21:01:33
问题 I'm trying to share some memory with an other forked+execed process using shmget and shmat : char test[]="test"; int shID; char *shptr; key_t shkey = 2404; shID = shmget(shkey, sizeof(char)*(strlen(test)+1), IPC_CREAT | 0666); if (shID >= 0) { shptr = shmat(shID, 0, 0); if (shptr==(char *)-1) { perror("shmat"); } else { memcpy(shptr, &test, strlen(test)+1); .... //forking and execing .... shmdt(shptr); } } else { perror("shmget"); } This works fine. The thing is that test[] is going to be a

Current C11 Implementation Status (<threads.h>)?

試著忘記壹切 提交于 2019-12-23 20:31:18
问题 I'm curious what the status of C11 implementations are, specifically in regard to the optional <threads.h> . Do any platforms currently support the interfaces? If not, are there any plans to implement the interfaces in terms of POSIX and/or WinAPI? Is anyone else planning on using the interfaces described in C11 ( thrd_t , mtx_t , cond_t , etc...)? 来源: https://stackoverflow.com/questions/23400686/current-c11-implementation-status-threads-h

Is it possible to set the POSIX group of a file?

浪尽此生 提交于 2019-12-23 19:17:05
问题 I am aware that it's possible to set the owner of a file using Files.setOwner: Files.setOwner(Path path, UserPrincipal owner); However what about the POSIX group ? There is no such Files.setGroup() method in the API, and not even using the FileOwnerAttributeView works, as there is only setOwner too. Is it possible at all? 回答1: If your app is working on POSIX systems exclusively, there's PosixFileAttributeView.setGroup(). 来源: https://stackoverflow.com/questions/18686099/is-it-possible-to-set

Why can't get data from tail -f?

混江龙づ霸主 提交于 2019-12-23 19:05:55
问题 In my program I'm redirecting output of child process to pipe and in parent getting this result and doing something (this is not important). But my program doesn't work when I'm using tail -f test.txt command and doesn't recieve any data during tail is running, and getting this data only after tail is finished (or killed). At first I have thought that problem was that tail -f doesn't flushing and that's why no data I can recieve, but when I have tried to redirect output of tail -f to some

Internal and external encoding vs. Unicode

有些话、适合烂在心里 提交于 2019-12-23 17:35:06
问题 Since there was a lot of missinformation spread by several posters in the comments for this question: C++ ABI issues list I have created this one to clarify. What are the encodings used for C style strings? Is Linux using UTF-8 to encode strings? How does external encoding relate to the encoding used by narrow and wide strings? 回答1: Implementation defined. Or even application defined; the standard doesn't really put any restrictions on what an application does with them, and expects a lot of

OpenSSL SSL_write from multiple buffers / SSL_writev

痞子三分冷 提交于 2019-12-23 16:50:27
问题 I've written a networking server that uses OpenSSL for SSL/TLS. The server sends and receives large blocks of data and performs various transformations in between. For performance reasons, transformations are done mainly using vector information (see iovec from POSIX) that avoids expensive memory moves (memcpy() etc.). When data are ready to be sent, I use writev() POSIX function that gathers data from the memory using these vectors and it sends that usually as one network packet. Now with

Preventing SIGPIPE

余生颓废 提交于 2019-12-23 16:23:26
问题 Let's consider the following example. I have a parent process that creates a pipe, spawns a child and read the child's standard output using this pipe. At some point, the parent process is no longer interested in the child's output, and closes the read end of the pipe. Apparently, if the child keeps writing, will this result in the child process receiving a SIGPIPE signal. Question: is there a way to redirect the child's output to /dev/null so that it still keeps running and producing output,

Are Unix/Linux system calls part of POSIX library functions?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 15:58:17
问题 Are Unix/Linux system calls all or mostly in POSIX? Many Linux/Unix programming books say that POSIX library functions may be wrappers of OS system calls, or may be not. E.g. http://www.makelinux.net/books/lkd2/ch05lev1sec1, and https://www.safaribooksonline.com/library/view/understanding-the-linux/0596005652/ch10s01.html A part (called the Single UNIX Specification) of POSIX defines UNIX. Therefore I think POSIX defines the system calls of Unix (and of Linux). Then are Unix/Linux system

Linux Pthread argument

痞子三分冷 提交于 2019-12-23 15:10:41
问题 This is my code. It's very simple. #include <stdio.h> #include <stdlib.h> #include <pthread.h> void *func(void *arg) { printf("ID=%d\n", *(int*)arg); pthread_exit(NULL); } int main() { pthread_t pt[4]; int i; for (i = 0; i < 4; i++) { int temp = i; pthread_create(&pt[i], NULL, func, (void*)&temp); } sleep(1); return 0; } I compiled it: gcc p_test.c -lpthread I ran it. It printed 2 2 3 3 . I ran it again. It printed 2 3 3 2 . My problem is: Why was 2 or 3 printed twice? Why didn't it print 1 3