posix

Windows-equivalent of POSIX srandom(…) and random() functions?

元气小坏坏 提交于 2019-12-12 14:21:17
问题 I'm trying to port some code over from UNIX to Windows, and I need an implementation of POSIX srandom(x) and random() functions that, for a given seed x , generate the same number sequence as the one that conforms to POSIX.1-2001. What are some of the available options on Windows? 回答1: srandom and family are members of glibc. You can probably copy the source code from glibc for srandom/random into your application, as long as it's license compatible. If you're looking for another

C++ Copy directory recursive under unix

余生颓废 提交于 2019-12-12 14:10:54
问题 There are no any examples of the functions ready for use on c++ without additional libs to Copy recursive files and folders to the new location. Some alternative to system("cp -R -f dir"); call. I'm only found this Recursive directory copying in C example on the thread answer, but its not ready for use and I'm not sure that this example is correct to start with. Maybe somebody have working example on the disk? 回答1: Here is a complete running example for recursive copying with POSIX and

POSIX timer runs at twice the expected frequency

纵然是瞬间 提交于 2019-12-12 13:52:17
问题 In order to create a high accuracy timer, I have written a module that instantiates a POSIX timer using the timer_create() function. It uses CLOCK_REALTIME as its clock kind, SIGEV_SIGNAL as notification method and SIGRTMIN as the signal number. Its signal handler does nothing but a sem_post(). The timer is started using timer_settime(), with any number of milliseconds as the timer interval. The user of the module can wait for a timer-tick; the wait functionality is essentially implemented by

POSIX O_DIRECT vs Windows FILE_FLAG_WRITE_THROUGH & FILE_FLAG_NO_BUFFERING

半腔热情 提交于 2019-12-12 13:05:08
问题 From what I can gather, then using POSIX O_DIRECT with open() on blocking device files works just the same way as combining both FILE_FLAG_WRITE_THROUGH and FILE_FLAG_NO_BUFFERING with CreateFile() on Windows - is this correctly assumed by me? Open: O_DIRECT Try to minimize cache effects of the I/O to and from this file. In general this will degrade performance, but it is useful in special situations, such as when applications do their own caching. File I/O is done directly to/from user space

How to iterate over the characters of a string in a POSIX shell script?

强颜欢笑 提交于 2019-12-12 12:23:19
问题 A POSIX compliant shell shall provide mechanisms like this to iterate over collections of strings: for x in $(seq 1 5); do echo $x done But, how do I iterate over each character of a word? 回答1: It's a little circuitous, but I think this'll work in any posix-compliant shell. I've tried it in dash , but I don't have busybox handy to test with. var='ab * cd' tmp="$var" # The loop will consume the variable, so make a temp copy first while [ -n "$tmp" ]; do rest="${tmp#?}" # All but the first

How do I read Unicode-16 strings from a file using POSIX methods in Linux?

穿精又带淫゛_ 提交于 2019-12-12 11:15:56
问题 I have a file containing UNICODE-16 strings that I would like to read into a Linux program. The strings were written raw from Windows' internal WCHAR format. (Does Windows always use UTF-16? e.g. in Japanese versions) I believe that I can read them using raw reads and the converting with wcstombs_l. However, I cannot figure what locale to use. Runing "locale -a" on my up-to-date Ubuntu and Mac OS X machines yields zero locales with utf-16 in their names. Is there a better way? Update: the

How to open Perl file handle to write data via sudo (or as another user)

百般思念 提交于 2019-12-12 10:54:02
问题 I'd like to write data to a file, but the file handle should be opened with access permissions for a specific user. Thus, the following statement: open (FH, "> $filename") or die "$@\n"; would allow writing to a file as that particular user. Is there a way to do this within a Perl script, without the entire script being run with sudo -u $username ? 回答1: There are two established ways. Stackers, you are invited to edit this answer to fill in the drawbacks for each. Run the program with sudo .

How to use named mutex at linux?

99封情书 提交于 2019-12-12 10:24:33
问题 I'd like to use named mutex at linux for multi process. I searched at google and find some APIs. But, it's hard to break out the coding. I found two apis and it looks set name and be shared between processes. pthread_mutexattr_setname_np pthread_mutexattr_setpshared(&mtx_attr, PTHREAD_PROCESS_SHARED); Could somebody give me hint or example? 来源: https://stackoverflow.com/questions/46313748/how-to-use-named-mutex-at-linux

Thread Performance in Android

本小妞迷上赌 提交于 2019-12-12 10:22:33
问题 Is there any way to monitor the performance of a thread on Android phone. As in any POSIX library? I want to find the time taken by a "thread" during execution, while many other applications might also be running. Thank You. 回答1: Linux supports a per-thread CPU usage timer. Time advances when a thread is executing or (I think) blocked on disk I/O, but does not advance when other threads are executing or the current thread is waiting for an event (e.g. Object.wait()). You can use it from an

How to wake up a sleeping thread from the main Thread?

筅森魡賤 提交于 2019-12-12 10:14:44
问题 I have a capture program which in addition do capturing data and writing it into a file also prints some statistics.The function that prints the statistics static void report(void) { /*Print statistics*/ } is called roughly every second using an ALARM that expires every second.So The program is like void capture_program() { pthread_t report_thread while() { if(pthread_create(&report_thread,NULL,report,NULL)){ fprintf(stderr,"Error creating reporting thread! \n"); } /* Capturing code ---------