I’m trying to write a mock-shell in c on linux, and got stuck on this problem: I need to run some processes in the background, and some processes in the foreground. To prevent the foreground processes from becoming zombies, I can use wait(), but how do I prevent the background processes from becoming zombies? Answer You cannot prevent any process
Tag: c++
How atomic the fork() syscall actually is?
Assuming check_if_pid_exists(pid) returns true when a process with such a pid exists (but possibly hasn’t been running yet) or false when there is no process with such pid, is there any chance in parent code for a race condition when the fork() returned the child pid, however the kernel hasn’t had a chance to initialize the data structures so that
C: Why passing a float/double literal for an int argument does not raise warnings?
Consider this code: I compile it with gcc -Wall sleep.c -o sleep with no warnings. Running it gives me time ./sleep real 0m0,001s user 0m0,001s sys 0m0,000s .1 magically becomes 0, but my question is why no warnings? I’m using stock gcc 7.3.0 in Lubuntu 18.04 Answer It’s a valid conversion – the fractional part is discarded when you convert
Cannot get memory allocated from `flex_array_alloc` when requesting a relatively big size in linux kernel
I’m doing some linux kernel development. And I’m going to allocate some memory space with something like: ptr = flex_array_alloc(size=136B, num=1<<16, GFP_KERNEL) And ptr turns out to be NULL every time I try. What’s more, when I change the size to 20B or num to 256,there’s nothing wrong and the memory can be obtained. So I want to know if
Program can compile on Mac, but not Linux. Gets error: converting to from initializer list
I have a program which will successfully compile on my mac but when I try on my linux desktop it cannot. Instead, I get the following error: like 12 of plot.cpp looks like this: This vector is initialised in header.h, here: I have looked around a bit and I suspect the error is coming from the line in header.h where
Unsigned long into char array
Here is an example of my code : My question is, why does this last memcpy works ? i would expect to put CRYPTO and not &CRYPTO in arguments… For me, CRYPTO is the value i want so 0xe8ba8fa3 and &CRYPTO the address. And for me, CRYPTO is not a pointer, so why i need to use memcpy with &CRYPTO
How do the clock function works in operating systems?
I don’t understand how clock function works within an operating system. First the documentation for clock function in www.cplusplus.com is: As far as I understand, the clock function must access directly some register within the CPU that is a counter for CPU cycles. How is this possible? I mean, any register of 32 bits would overflow very soon if it
How to create a navigation menu in dotnet application?
I have created a console application which have a menu that allow me to navigate between the menu items. I handle the navigation logic in this method: here the full class. Now on windows all works well, but when I run this application on my linux with systemd I get: Unhandled Exception: System.InvalidOperationException: Cannot read key when either application does
Storing and accessing an array of struct from shared memory
I am writing a program on a hotel reservation system and have declared a struct Room as follows: I use a variable read from an input file to create an array of n structs which is all the rooms in the hotel. I then create the shared memory space and attach it, but when I try to access it after,
How to reproduce the accept error in Linux
I’m learning Unix Network Programming Volume 1, I want to reproduce the accept error for RST in Linux. server: call socket(), bind(), listen(), and sleep(10) client: call socket(), connect(), setsockopt() of LINGER, close() and return server: call accept() I think that the 3rd steps will get an error like ECONNABORTED, but not. Do I want to know why? I will