systems-programming

How to take advantage of the VDSO object with your own programming language?

こ雲淡風輕ζ 提交于 2019-12-03 12:58:01
问题 Recent Linux kernels (at least on amd64) provide a magic object file called linux-vdso.so.1 that abstracts away the syscall interface to the kernel, allowing the kernel to choose the optimal calling convention. If you write code in C, the glibc automatically uses this object. Now, if I want to write a program without using the glibc, how can I use this object? Is the interface it provides documented somewhere? What about the calling convention? 回答1: It depends if your implementation is using

What's the shortest code to write directly to a memory address in C/C++?

拈花ヽ惹草 提交于 2019-12-03 10:58:25
I'm writing system-level code for an embedded system without memory protection (on an ARM Cortex-M1, compiling with gcc 4.3) and need to read/write directly to a memory-mapped register. So far, my code looks like this: #define UART0 0x4000C000 #define UART0CTL (UART0 + 0x30) volatile unsigned int *p; p = UART0CTL; *p &= ~1; Is there any shorter way (shorter in code, I mean) that does not use a pointer? I looking for a way to write the actual assignment code as short as this (it would be okay if I had to use more #defines): *(UART0CTL) &= ~1; Anything I tried so far ended up with gcc

How can I run a list of commands in parallel?

岁酱吖の 提交于 2019-12-03 08:17:12
问题 I have a file containing command lines that I want to run. This file contains around 2,000 lines. I have 8 cores available. Is it possible to parse the file and start 8 processes, then execute another one from the file whenever one of the programs finishes? I want this to continue until the end of file is reached. 回答1: You can use xargs to read in the file, while limiting the maximum number of processes to the number of available cores. For example: cores=$(fgrep -c processor /proc/cpuinfo)

Using sigaction(), c

半城伤御伤魂 提交于 2019-12-03 07:47:28
I was doing a little reading about sigaction() (sources are from my course notes) and I'm not sure I understand this text: The signal mask is calculated and installed only for the duration of the signal handler. By default, the signal “sig” is also blocked when the signal occurs. Once an action is installed for a specific signal using sigaction, it remains installed until another action is explicitly requested. Does this mean that the default signal mask is restored after returning form the signal handler? Also, do I have to re-install the handler after using it, as if I was using signal() ?

How can I run a list of commands in parallel?

徘徊边缘 提交于 2019-12-02 20:55:00
I have a file containing command lines that I want to run. This file contains around 2,000 lines. I have 8 cores available. Is it possible to parse the file and start 8 processes, then execute another one from the file whenever one of the programs finishes? I want this to continue until the end of file is reached. You can use xargs to read in the file, while limiting the maximum number of processes to the number of available cores. For example: cores=$(fgrep -c processor /proc/cpuinfo) xargs --arg-file=/tmp/foo \ --max-procs=$cores \ --replace \ --verbose \ /bin/sh -c "{}" Use GNU parallel .

How do I make sure that file handle for every `Child` process is released after every iteration?

久未见 提交于 2019-12-02 13:26:29
问题 I have the following program taken from the Rust docs for std::process::Command. It stops working after some iterations. use std::process::Command; use std::process::Stdio; fn main() { loop { let mut echo_child = Command::new("echo") .arg("oh no a tpyo") .stdout(Stdio::piped()) .spawn() .expect("failed to start 'echo'"); let echo_out = echo_child.stdout.expect("failed to open 'echo' stdout"); let sed_child = Command::new("sed") .arg("s/tpyo/typo/") .stdin(Stdio::from(echo_out)) .stdout(Stdio:

return value in vfork() system call

徘徊边缘 提交于 2019-12-01 17:37:06
Considering the below code : int main() { int pid; pid=vfork(); if(pid==0) printf("child\n"); else printf("parent\n"); return 0; } In case of vfork() the adress space used by parent process and child process is same, so single copy of variable pid should be there. Now i cant understand how this pid variable can have two values returned by vfork() i.e. zero for child and non zero for parent ? In case of fork() the adress space also gets copied and there are two copy of pid variable in each child and parent, so I can understand in this case two different copies can have different values returned

boost::thread data structure sizes on the ridiculous side?

感情迁移 提交于 2019-12-01 00:45:16
Compiler: clang++ x86-64 on linux. It has been a while since I have written any intricate low level system code, and I ussualy program against the system primitives (windows and pthreads/posix). So, the in#s and out's have slipped from my memory. I am working with boost::asio and boost::thread at the moment. In order to emulate synchronous RPC against an asynchronous function executor ( boost::io_service with multiple threads io::service::run 'ing where requests are io_serviced::post 'ed), I am using boost synchronization primitives. For curiosities sake I decided to sizeof the primitives.

boost::thread data structure sizes on the ridiculous side?

孤街浪徒 提交于 2019-11-30 18:11:14
问题 Compiler: clang++ x86-64 on linux. It has been a while since I have written any intricate low level system code, and I ussualy program against the system primitives (windows and pthreads/posix). So, the in#s and out's have slipped from my memory. I am working with boost::asio and boost::thread at the moment. In order to emulate synchronous RPC against an asynchronous function executor ( boost::io_service with multiple threads io::service::run 'ing where requests are io_serviced::post 'ed), I

We have to use C “for performance reasons” [closed]

回眸只為那壹抹淺笑 提交于 2019-11-30 10:36:35
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . In this age of many languages, there seems to be a great language for just about every task and I find myself professionally struggling against a mantra of " nothing but C is fast ", where fast is really intended to mean "fast enough". I work with very rational open-minded people, who like to compare numbers,