systems-programming

Does 64-bit Windows use KERNEL64?

谁说胖子不能爱 提交于 2019-11-30 08:21:09
I was looking at some libraries with dumpbin and I noticed that all the 64-bit versions were linked to KERNEL32. Is there no KERNEL64 on 64-bit Windows? If not, why? All my operating systems are 32-bit so I can't just look. A google search brings up nothing worthwhile so I suspect that there is no KERNEL64 but I'm still curious as to why this is. EDIT: I found this later which is pretty useful. MSDN guide to x64 It's always called kernel32.dll , even on 64-bit windows. This is for the same compatibility reasons that system32 contains 64-bit binaries, while syswow64 contains 32-bit binaries. On

On the use and abuse of alloca

安稳与你 提交于 2019-11-30 06:54:39
问题 I am working on a soft-realtime event processing system. I would like to minimise as many calls in my code that have non-deterministic timing. I need to construct a message that consists of strings, numbers, timestamps and GUID's. Probably a std::vector of boost::variant 's. I have always wanted to use alloca in past code of a similar nature. However, when one looks into systems programming literature there are always massive cautions against this function call. Personally I can't think of a

On the use and abuse of alloca

风流意气都作罢 提交于 2019-11-28 23:11:03
I am working on a soft-realtime event processing system. I would like to minimise as many calls in my code that have non-deterministic timing. I need to construct a message that consists of strings, numbers, timestamps and GUID's. Probably a std::vector of boost::variant 's. I have always wanted to use alloca in past code of a similar nature. However, when one looks into systems programming literature there are always massive cautions against this function call. Personally I can't think of a server class machine in the last 15 years that doesn't have virtual memory, and I know for a fact that

How to make thread in C without using POSIX library <pthread.h> [closed]

谁说我不能喝 提交于 2019-11-28 06:35:08
I want to implement the multiple threading in C without using any of the POSIX library. Any help would be appreciated. Not : Don't use fork() or vfork(). See: setjmp , longjmp , sigaltstack , sigaltstack for UNIX like systems. Also see: getcontext and setcontext , and more generally ucontext for BSDs and modern UNIXes. This page gives many examples of barebone implementations using these primitives and more. You can use atomic instructions to implement the locking primitives (mutex, semaphores). I also suggest looking at actual implementations of userland thread libraries to get some hints.

C/C++ How to tell if a program is already running?

我们两清 提交于 2019-11-28 01:50:28
问题 In a Windows environment, I don't want two instances of my program running at the same time. Related Is using a Mutex to prevent multiple instances of the same program from running safe? 回答1: I think you need to consider your scenario a bit before going forward. There are many different interpretations of "running the same program" more than once. For instance do you Once per machine Once per logon session Once per user All of these have different, albeit similar, solutions. The easiest one

mmap on /proc/pid/mem

▼魔方 西西 提交于 2019-11-28 01:04:15
Has anybody succeeded in mmap'ing a /proc/pid/mem file with Linux kernel 2.6? I am getting an ENODEV (No such device) error. My call looks like this: char * map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, mem_fd, offset); And I have verified by looking at the /proc/pid/maps file while debugging that, when execution reaches this call, offset has the value of the top of the stack minus PAGE_SIZE. I have also verified with ptrace that mmap is setting errno to ENODEV. ephemient See proc_mem_operations in /usr/src/linux/fs/proc/base.c : /proc/.../mem does not support mmap . 来源: https:/

Why does this program print “forked!” 4 times?

北城以北 提交于 2019-11-28 01:03:00
Why does this program print “forked!” 4 times? #include <stdio.h> #include <unistd.h> int main(void) { fork() && (fork() || fork()); printf("forked!\n"); return 0; } Jean-Baptiste Yunès The first fork() returns a non-zero value in the calling process (call it p0) and 0 in the child (call it p1). In p1 the shortcircuit for && is taken and the process calls printf and terminates. In p0 the process must evaluate the remainder of the expression. Then it calls fork() again, thus creating a new child process (p2). In p0 fork() returns a non-zero value, and the shortcircuit for || is taken, so the

Why use bzero over memset?

假如想象 提交于 2019-11-27 16:56:24
In a Systems Programming class I took this previous semester, we had to implement a basic client/server in C. When initializing the structs, like sock_addr_in , or char buffers (that we used to send data back and forth between client and server) the professor instructed us to only use bzero and not memset to initialize them. He never explained why, and I'm curious if there is a valid reason for this? I see here: http://fdiv.net/2009/01/14/memset-vs-bzero-ultimate-showdown that bzero is more efficient due to the fact that is only ever going to be zeroing memory, so it doesn't have to do any

how to make a process daemon

拥有回忆 提交于 2019-11-27 16:52:41
I am trying to understand how can I make my program a daemon.So some things which I came across are In general, a program performs the following steps to become a daemon: Call fork( ) . In the parent, call exit( ) . This ensures that the original parent (the daemon's grandparent) is satisfied that its child terminated, that the daemon's parent is no longer running, and that the daemon is not a process group leader. This last point is a requirement for the successful completion of the next step. Call setsid( ) , giving the daemon a new process group and session, both of which have it as leader.

*nix select and exceptfds/errorfds semantics

懵懂的女人 提交于 2019-11-27 13:51:49
The select syscall takes 3 filedescriptor sets for watching fds for readable/writeable and "exceptions" on filedescriptor. My select man page doesn't state much about the exceptfd descriptor set. What is it used for; what kind of exceptions can and will it notify on file descriptors? I'm assuming this can be different for the descriptor type... whether it's a TCP socket, a pipe, a tty , etc.). Does anyone have more info on what kind of errors select can report on the different kinds of descriptors? It is sometimes thought that exceptfds is needed to detect errors, but that is a misconception.