Skip to content
Advertisement

Tag: fork

Multi-Process Shell in C, using Pipes [Linux]

I’m trying to code a shell in C that supports multi-pipe process handling, depending on the amount of separate processes given by the user, and each separated by a “|” symbol. The shell forks the amount of processes into a child for each process. Here’s an example: result: 1 But I’m having trouble with communicating between children and finally to

What happens to pthread_key_create() generated keys after a process fork?

From pthread_key_create FreeBSD man page: /comment … The pthread_key_create() function creates a thread-specific data key visible to all threads in the process. Key values provided by pthread_key_create() are opaque objects used to locate thread-specific data. Although the same key value may be used by different threads, the values bound to the key by pthread_setspecific() are maintained on a per-thread basis

fork() giving wrong output in linux (reverse output)

I have written code in C as follows Output as shown in ubuntu 20 OS I am expecting that child process should be written first as after fork() is called child process’s printf() will be printed on screen and after that parent’s printf() will be printed but reverse is printed actually. Please help me why child process’s printf() is not

libuv: difference between fork and uv_spawn?

Recently I have been playing around with Libuv. I don’t get the programming model as far as child processes are concerned. For example look at the following code: Here the output printed on console is: In my understanding uv_spawn acts like fork(). In child process the value of r is 0 and in parent process it is non-zero. So from

Explain pipe and fork output

I am dealing with pipe and fork in Linux for the first time and I would be happy if someone could explain to me the output of the following program: (which line of code causes the output and is it through the son process or the parent process) The output of the program is: Answer fork() creates a child process

Can a fork child determine whether it is a fork or a vfork?

Within the child process, is there any way that it determine whether it was launched as a fork with overlay memory, or a vfork with shared memory? Basically, our logging engine needs to be much more careful (and not log some classes of activity) in vfork. In fork it needs to cooperate with the parent process in ways that it

Fork how many processes created confused

Say i have the following program So now what we have: Fork #1 creates an additional processes. so now we have two processes. Fork #2 is executed by two processes, creating two processes, for a total of four. My confusion is after the first fork we will have two processes P1(parent) and C1 (child). each process will execute the second

Why does read block on a pipe until the write end is closed?

I’m trying to bolster my understanding of things related to fork, exec, dup, and redirecting stdin/stdout/stderr by writing the following popen-type function: Compilation and execution: My question is about the read() – I don’t quite grok why does the read() is seemingly block until the child process has completed (thereby closing its end of the pipe)? Is it coincidence? You

getline() is repeatedly reading the file, when fork() is used

I am developing a simple shell program, a command line interpreter and I wanted to read input from the file line by line, so I used getline() function. At the first time, the program works correctly, however, when it reaches the end of the file, instead of terminating, it starts to read a file from the start and it runs

How to avoid read() from hanging in the following situation?

I have some code that forks a third-party application and redirects its standard output to the parent process, roughly as follows (no error handling here for brevity): I have no code for the third-party application, it is a proprietary binary. When running the third-party application in a terminal with the same arguments as used in the code above, it eventually

Advertisement