Skip to content
Advertisement

Tag: fork

Why is execvp() executing twice using fork()?

I am implementing a shell. When attempting a command other than changing directories, execvp() runs, the child terminates and a new child is created. When I change directories, the child does not terminate and a new child is created. Here is a sample of my code: cd ../; ls; runs correctly, except I have to Ctrl+D twice to end the

Using Fork for Command Line Arguements

I’m trying to execute the command “ls -l” but I’m not exactly sure how to approach it. This is what I’ve tried: However, the command doesn’t seem to work here. It works if I just simply use “ls” but I want to use “ls -l” is there another argument I have to pass to get this to work? Answer First

Fork process: Resume parent process while children terminated (Linux)

I’ve written a C++ application that waits until an event occurs (e.g. wait for incoming connection). After that event occured, it will continue by forking a child process that handles that event. So, my code looks essentially like this: My expectation now was that the child process will terminate (because of exit(0) and/or return). Indeed, it leaves the while loop,

Child process starts after parent process

I have a simple code to test the fork() function. It didn’t work as I expected. My expectation is: parent’s result and child’s result appear alternately. Can someone explain this and teach me how to fix it? Thanks! Answer The explanation is simple. Scheduling of processes is up to the kernel. If this is a single core processor then in

How fork() function works in this program?

I’m having some trouble with this program. I know what a fork() function does. It is used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. The parent returnes the child’s pid and the child returns 0. That said, I find hard to understand

Linux-C: reading from pipe returns first buffer written to it

This program simulates a variant of Dijkstra’s Producer/Consumer problem. A pipeline is first created followed by a child process using fork(). The child will then write to the pipe a crudely done randomly generated piece of “stock market ticker information”. After waiting for the child/producer process to write this information, the parent/consumer process will read it out. The first output

Interpreting STRACE output – pipes and forks

I have the following code written in C, taken from https://beej.us/guide/bgipc/html/multi/pipes.html: When compiling and running this code in the terminal using strace I get the following output: Can anybody explain, line by line, what is going on in the strace output? I’ve attempted to research how to interpret strace outputs but haven’t had any luck. Thanks in advance. Answer The

Counter increase in child & parent with fork()

I’ve a problem with this little program: I increase the counter in the child but in the parent the counter not increase… why? Thank you everyone Answer That’s because after fork, parent process and child process are different processes, and they each have their own copy of the variable count.

Advertisement