posix

How does the computer know the present date and time?

心已入冬 提交于 2019-12-26 12:22:07
问题 Please pardon my ignorance about this. I may have read this a long time ago, many years ago in Charles Petzold's Programming Windows, 4th Ed. book, and I must have forgotten it all. I remember the very first chapter had something to say about timer resolutions and clock-speeds of the CPU but I forget the details. I think in that he answers this question. But I could be imagining things. It's been a long while. While there is a related question here, the answer is not to my satisfaction as it

POSIX Threads, unique execution

旧巷老猫 提交于 2019-12-25 18:33:46
问题 Is there a way to be sure only 1 thread executes a specific function? for (i = startnotfirst; i < end; i++) { gl_rand = (float) lrand48(); fprintf(stderr, "\nTHREADING - #ID: %d - THIS IS MY RAND: %f", *mytid,rand); to_open = (rand / (float) INT_MAX) < (points->p[i].cost / z); if (to_open) { //printf("\nRANDOM: %f \nINT_MAX: %d \npointsDistance(cost): %f \nZ: %f \n\n RESULT: %f < %f\n\n\n",rand ,INT_MAX,points->p[1].cost , z,(rand / (float) INT_MAX),(points->p[i].cost / z)); fprintf(stderr, "

C fork and pipe program with non-deterministic output

一笑奈何 提交于 2019-12-25 18:19:53
问题 Lets consider the following code (please do not write, that there are naming problems, structuring problems, etc, I know this, too). It was written to write out the random generated x,y,z and r (and pid) numbers for its 3 children, but it often happens that it only prints two/one "Got this..." lines, and I dont know, why. Could you please explain me, what the problem is, or correct my code? #include <stdlib.h> #include <stdio.h> #include <sys/types.h> //fork #include <sys/stat.h> #include

Using switch statements to fork two processes

做~自己de王妃 提交于 2019-12-25 09:20:55
问题 I'm taking an intro to C course and I've become a bit stumped on the first assignment. We've been tasked with creating a parent processes and two child processes. All of the examples the text has shown us so far involve switch statements with one parent and one child. I'm a bit confused about how to translate this into one parent and two child processes. Here is what I have so far: #include <stdio.h> int main() { int i, pid, status; pid = fork(); switch(pid) { case -1: /* An error has

Spinner in Shell

别等时光非礼了梦想. 提交于 2019-12-25 08:49:45
问题 I found this for BASH, but I want to do the same thing with shell ( #!/bin/sh ). The twist is to make it a timer also, so like wait 60 seconds for example until it ends. 回答1: Fadi's own solution is helpful (and comes by courtesy of Adam Katz's comment on the linked answer), but comes with 2 caveats: The spinner, due to using \r , only works at the beginning of a line. Per POSIX, sleep only supports integral seconds. It may also not be readily obvious where to test for whether the operation is

R how to convert timestamps into multiple timezones in the same column

瘦欲@ 提交于 2019-12-25 08:15:40
问题 I have a dataframe that contains two character variables: one is a timestamp and the other is a US state. I have been unsuccessfully trying to convert each timestamp to a POSIX object, with time zone assigned according to the corresponding value for state: Eastern Time (EST) for Florida (FL) and Central Time (CST6CDT) for Texas (TX). However, no matter what I try, R will only return either all of the time stamps in a single time zone or else as a string containing the number of seconds since

struct itimerspec as timer_create's parameter invalid argument

陌路散爱 提交于 2019-12-25 07:58:24
问题 I was trying POSIX timers togheter with POSIX signals handling. When I try to excecute the code you can find downhere, I get: Errore timer_settime: Invalid argument On GAPIL book, that is based upon Advanced Linux Programming and Unix network programming, I read that this can happen when inside new_value.value you specified a negative time value or a number of nanoseconds higher than 999999999. But I think that parameters I have used are okay... #include <string.h> #include <stdio.h> #include

struct itimerspec as timer_create's parameter invalid argument

假装没事ソ 提交于 2019-12-25 07:56:03
问题 I was trying POSIX timers togheter with POSIX signals handling. When I try to excecute the code you can find downhere, I get: Errore timer_settime: Invalid argument On GAPIL book, that is based upon Advanced Linux Programming and Unix network programming, I read that this can happen when inside new_value.value you specified a negative time value or a number of nanoseconds higher than 999999999. But I think that parameters I have used are okay... #include <string.h> #include <stdio.h> #include

What does constitute one character for regcomp? Which multibyte encoding does determine this?

血红的双手。 提交于 2019-12-25 07:51:02
问题 regcomp (from glibc) is a POSIX function for compiling regular expressions. int regcomp(regex_t *restrict preg, const char *restrict pattern, int cflags); There are some constructions in regular expressions which depend on the idea of a single character, for example [abc] . If a multibyte encoding is used and a multibyte letter is used in the expression, the interpretation would be different if it treated either as a byte-sequence or a sequence of multibyte letters. Here I illustrate this

Find out default language on Linux

允我心安 提交于 2019-12-25 03:19:09
问题 Is there a way to find out the default language of a Linux system from C? Is there a POSIX API for this? E.g. I'd like to have a string in human readable format, i.e. "German" or "Deutsch" on a German system, "French" or "Francais" on a French system etc. Is there something like this? Thanks! 回答1: Usually, the LANG environment variable contains that information in the format like "de_DE.UTF-8". You can retrieve it using the getenv function. EDIT: For more sophisticated internationalization,