posix-api

What is a good way to simulate O_NOFOLLOW on systems without this flag?

瘦欲@ 提交于 2020-01-15 12:10:58
问题 I would like to safely be able to simulate open with O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW and O_CREAT | O_WRONLY | O_APPEND | O_NOFOLLOW on systems that do not support O_NOFOLLOW . I can somewhat achieve what I am asking for with: struct stat lst; if (lstat(filename, &lst) != -1 && S_ISLNK(lst.st_mode)) { errno = ELOOP; return -1; } mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; int fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW, mode); but then I

Is O_LARGEFILE needed just to write a large file?

♀尐吖头ヾ 提交于 2019-12-17 16:29:03
问题 Is the O_LARGEFILE flag needed if all that I want to do is write a large file ( O_WRONLY ) or append to a large file ( O_APPEND | O_WRONLY )? From a thread that I read titled "Cannot write >2gb index file" on the CLucene-dev mailing list, it appears that O_LARGEFILE might be needed to write large files, but participants in that discussion are using O_RDWR , not O_WRONLY , so I am not sure. 回答1: O_LARGEFILE should never be used directly by applications. It's to be used internally by the 64-bit

Do I need an extern “C” block to include standard C headers?

两盒软妹~` 提交于 2019-12-17 07:47:32
问题 Do I need an extern "C" {} block to include standard C headers in a C++ program. Only consider standard C headers which do not have counterparts in C++. For example: extern "C" { #include <fcntl.h> #include <unistd.h> } 回答1: The behavior of <fcntl.h> and <unistd.h> in C++ is not specified by the standard (because they are also not part of the C89 standard). That said, I have never seen a platform where they (a) exist and (b) actually need to be wrapped in an extern "C" block. The behavior of

Will POSIX system(3) call to an asynchronous shell command return immediately?

别说谁变了你拦得住时间么 提交于 2019-12-13 02:42:35
问题 For example, system("sh /mydir/some-script.sh &") 回答1: system("sh /mydir/some-script.sh &") executes /bin/sh -c 'sh /mydir/some-script.sh &' system will return as soon as outer shell returns, which will be immediately after it launches the inner shell. Neither shell will wait for some-script.sh to finish. $ cat some-script.sh sleep 1 echo foo $ /bin/sh -c 'sh some-script.sh &' ; echo bar ; sleep 2 bar foo 回答2: Yes, the shell will fork the script and return immediately, but you don't have an

Swift metal parallel sum calculation of array on iOS

对着背影说爱祢 提交于 2019-12-06 09:13:11
问题 Based on @Kametrixom answer, I have made some test application for parallel calculation of sum in an array. My test application looks like this: import UIKit import Metal class ViewController: UIViewController { // Data type, has to be the same as in the shader typealias DataType = CInt override func viewDidLoad() { super.viewDidLoad() let data = (0..<10000000).map{ _ in DataType(200) } // Our data, randomly generated var start, end : UInt64 var result:DataType = 0 start = mach_absolute_time(

Swift metal parallel sum calculation of array on iOS

偶尔善良 提交于 2019-12-04 15:31:19
Based on @Kametrixom answer , I have made some test application for parallel calculation of sum in an array. My test application looks like this: import UIKit import Metal class ViewController: UIViewController { // Data type, has to be the same as in the shader typealias DataType = CInt override func viewDidLoad() { super.viewDidLoad() let data = (0..<10000000).map{ _ in DataType(200) } // Our data, randomly generated var start, end : UInt64 var result:DataType = 0 start = mach_absolute_time() data.withUnsafeBufferPointer { buffer in for elem in buffer { result += elem } } end = mach_absolute

Is O_NONBLOCK being set a property of the file descriptor or underlying file?

偶尔善良 提交于 2019-12-03 05:49:23
问题 From what I have been reading on The Open Group website on fcntl, open, read, and write, I get the impression that whether O_NONBLOCK is set on a file descriptor, and hence whether non-blocking I/O is used with the descriptor, should be a property of that file descriptor rather than the underlying file. Being a property of the file descriptor means, for example, that if I duplicate a file descriptor or open another descriptor to the same file, then I can use blocking I/O with one and non

Is O_NONBLOCK being set a property of the file descriptor or underlying file?

喜夏-厌秋 提交于 2019-12-02 19:12:13
From what I have been reading on The Open Group website on fcntl , open , read , and write , I get the impression that whether O_NONBLOCK is set on a file descriptor, and hence whether non-blocking I/O is used with the descriptor, should be a property of that file descriptor rather than the underlying file. Being a property of the file descriptor means, for example, that if I duplicate a file descriptor or open another descriptor to the same file, then I can use blocking I/O with one and non-blocking I/O with the other. Experimenting with a FIFO, however, it appears that it is not possible to

SIGKILL signal handling

﹥>﹥吖頭↗ 提交于 2019-11-30 14:19:18
If a linux process is waiting for I/O (i.e it is in SLEEP state) and a SIGKILL signal is issued against it, upon termination ( STOPPED state) will it pass through RUNNING or READY state? In other words, for a process to handle a system interrupt such as one generated by SIGKILL is it necessary to pass through RUNNING or READY state ? Knowing that under normal circumstances a process can handle an interrupt from kernel and knowing that SIGKILL has a quite contradictory purpose of killing an unresponsive signal, I was doubtful about how much control is given to the process being killed, if any

SIGKILL signal handling

人走茶凉 提交于 2019-11-29 21:26:01
问题 If a linux process is waiting for I/O (i.e it is in SLEEP state) and a SIGKILL signal is issued against it, upon termination ( STOPPED state) will it pass through RUNNING or READY state? In other words, for a process to handle a system interrupt such as one generated by SIGKILL is it necessary to pass through RUNNING or READY state ? Knowing that under normal circumstances a process can handle an interrupt from kernel and knowing that SIGKILL has a quite contradictory purpose of killing an