systems-programming

Using sigaction(), c

萝らか妹 提交于 2019-12-21 01:57:29
问题 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

return value in vfork() system call

核能气质少年 提交于 2019-12-19 18:16:14
问题 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

Does 64-bit Windows use KERNEL64?

笑着哭i 提交于 2019-12-18 12:48:28
问题 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 回答1: It's always called kernel32.dll , even on 64-bit windows. This is for the

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

自作多情 提交于 2019-12-17 16:45:15
问题 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; } 回答1: 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)

What happens to an open file handle on Linux if the pointed file gets moved or deleted

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-16 22:37:11
问题 What happens to an open file handle on Linux if the pointed file meanwhile gets: Moved away -> Does the file handle stay valid? Deleted -> Does this lead to an EBADF, indicating an invalid file handle? Replaced by a new file -> Does the file handle pointing to this new file? Replaced by a hard link to a new file -> Does my file handle "follow" this link? Replaced by a soft link to a new file -> Does my file handle hit this soft link file now? Why I'm asking such questions: I'm using hot

How can I know the service name?

给你一囗甜甜゛ 提交于 2019-12-14 03:44:24
问题 This code from Stevens et al., Advanced Programming in the Unix Environment, Figure 16.17 is a server program to provide system uptime : #include "apue.h" #include <netdb.h> #include <errno.h> #include <syslog.h> #include <sys/socket.h> #define BUFLEN 128 #define QLEN 10 #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256 #endif extern int initserver(int, const struct sockaddr *, socklen_t, int); void serve(int socked); int main(int argc, char *argv[]) { struct addrinfo *ailist, *aip; struct

How to call UNIX sort command on data in pipe

我只是一个虾纸丫 提交于 2019-12-13 05:44:41
问题 I am creating a C program and with it I am setting up a pipe between separately forked process for interprocess communication. The first process has written the data I need into the pipe. However, with the second process reading from the pipe, I am trying to exec the process to become the UNIX sort command. I want to somehow call sort on the data in the pipe. How can I call sort on a pipe? On the commandline, I can sort by supplying the filename to sort as a commandline argument e.g. "sort -r

Is there a way to have a ioctl() with new(customized) command

故事扮演 提交于 2019-12-12 05:04:47
问题 I am working on a testing tool for nvme-cli(written in c and can run on linux). For SSD validation purpose, i was actually looking for a custom command(For e.g. I/O command, write and then read the same and finally compare if both the data are same) In user space i need to invoke minimum of 2 ioclt() one with write command(nvme_cmd_write) and another with read command(nvme_cmd_read) and compare both the buffer contents. Issue is actually when i wanted to send this command in parallel. At

c fork,exec,getpid problem

旧时模样 提交于 2019-12-11 16:53:56
问题 I'm new to c language and Linux. I have a problem related to fork(),getpid()and exec()function. I wrote a c program using fork() call the code of my program is following" code: #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> void fun() { printf("\n this is trial for child process"); } int main (int argc, char const *argv[]) { int i,status,pid,t; if(pid=fork()<0) { printf("\nfailed to create the process\n"); } if(pid=fork()==0) { printf("\n the child process

Is there any alternative for ioctl() in linux to interact with nvme drives

纵饮孤独 提交于 2019-12-11 09:30:07
问题 I am working on a testing tool for nvme-cli(written in c and can run on linux). For SSD validation purpose, we are actually looking for sending I/O commands to a particular Submission queue(IO Queue pair). We needed this because we wanted threading, but for threading to happen we need to send I/O requests to different queues else the I/O requests would be processed serially. So is there any way in ioctl() where we can specify the Submission queue IDs? OR Is there other thing similar to ioctl(