systems-programming

working of fork in c language [closed]

夙愿已清 提交于 2019-11-27 12:54:57
Now I have a problem in understanding the working of fork() system call. I write a code which is following : #include<stdio.h> int main() { int a, b; b=fork(); printf("\n the value of b = %d",b); } The output of this code is following : Now I don't understand why the output is like this ? After that i just add a line to my code and output is completely different. my code is following: int main() { int a, b; b=fork(); When i run the code the output is following 2389my name is manish the value of b = 0 Now I'm totally confused about the working of fork() call. My question are following: How fork

Zombie processes

时光毁灭记忆、已成空白 提交于 2019-11-27 02:15:06
问题 I'v some questions about zombie processes what the benefits from zombie process concept? know that the kernel keeps (PID,termination status, resource usage information) for zombie process what's the meaning of "resource usage information" how zombie's PPID() = 1 and it still zombie , (init reaps Zombies because it wait() by default) can any one write some C code to make a zombie it's parent is Init? can zombies refusing to release some lock on memory?? thanks in advance 回答1: -- what the

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

拜拜、爱过 提交于 2019-11-27 01:25:02
问题 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(). 回答1: 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,

Why use bzero over memset?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 22:30:11
问题 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

how to make a process daemon

佐手、 提交于 2019-11-26 18:46:58
问题 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

working of fork in c language [closed]

前提是你 提交于 2019-11-26 18:14:05
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . Now I have a problem in understanding the working of fork() system call. I write a code which is following : #include<stdio.h> int main() { int a, b; b=fork(); printf("\n the value of b = %d",b); } The output of

Implementing an N process barrier using semaphores

ε祈祈猫儿з 提交于 2019-11-26 18:07:08
问题 I'm currently training for an OS exam with previous iterations and I came across this: Implement a "N Process Barrier", that is, making sure that each process out of a group of them waits, at some point in its respective execution, for the other processes to reach their given point. You have the following ops available: init(sem,value), wait(sem) and signal(sem) N is an arbitrary number. I can make it so that it works for a given number of processes, but not for any number. Any ideas? It's OK

Programmatically get the cache line size?

我是研究僧i 提交于 2019-11-26 18:00:07
All platforms welcome, please specify the platform for your answer. A similar question: How to programmatically get the CPU cache page size in C++? spinfire On Linux (with a reasonably recent kernel), you can get this information out of /sys: /sys/devices/system/cpu/cpu0/cache/ This directory has a subdirectory for each level of cache. Each of those directories contains the following files: coherency_line_size level number_of_sets physical_line_partition shared_cpu_list shared_cpu_map size type ways_of_associativity This gives you more information about the cache then you'd ever hope to know,

*nix select and exceptfds/errorfds semantics

那年仲夏 提交于 2019-11-26 16:30:02
问题 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

Programmatically get the cache line size?

最后都变了- 提交于 2019-11-26 08:53:49
问题 All platforms welcome, please specify the platform for your answer. A similar question: How to programmatically get the CPU cache page size in C++? 回答1: On Linux (with a reasonably recent kernel), you can get this information out of /sys: /sys/devices/system/cpu/cpu0/cache/ This directory has a subdirectory for each level of cache. Each of those directories contains the following files: coherency_line_size level number_of_sets physical_line_partition shared_cpu_list shared_cpu_map size type