The tag has no usage guidance.

learn more… | top users | synonyms

65
votes
6answers
17k views

Why do we need to fork to create new processes?

In Unix whenever we want to create a new process, we fork the current process, creating a new child process which is exactly the same as the parent process; then we do an exec system call to replace ...
35
votes
4answers
6k views

Is there any UNIX variant on which a child process dies with its parent?

I have been studying the Linux kernel behaviour for quite some time now, and it's always been clear to me that: When a process dies, all its children are given back to the init process (PID 1) ...
33
votes
2answers
4k views

Why is the default process creation mechanism fork?

The UNIX system call for process creation, fork(), creates a child process by copying the parent process. My understanding is that this is almost always followed by a call to exec() to replace the ...
31
votes
4answers
7k views

What's the difference between running a program as a daemon and forking it into background with '&'?

What are the practical differences from a sysadmin point of view when deploying services on a unix based system?
18
votes
3answers
4k views

Fork vs Clone on 2.6 Kernel Linux

I have some confusion regarding fork and clone. I have seen that: fork is for processes and clone is for threads fork just calls clone, clone is used for all processes and threads Are either of ...
16
votes
3answers
11k views

When do you need 'nohup' if you're already forking using '&'?

First this question is related but definitely not the same as this very nice question: Difference between nohup, disown and & I want to understand something: when I do '&', I'm forking right?...
16
votes
4answers
10k views

After fork(), where does the child begin its execution?

I'm trying to learn UNIX programming and came across a question regarding fork(). I understand that fork() creates an identical process of the currently running process, but where does it start? For ...
16
votes
3answers
4k views

Does fork() immediately copy the entire process heap in Linux?

A fork() system call clones a child process from the running process. The two processes are identical except for their PID. Naturally, if the processes are just reading from their heaps rather than ...
16
votes
1answer
2k views

How does a fork bomb work?

WARNING DO NOT ATTEMPT TO RUN THIS ON A PRODUCTION MACHINE In reading the Wikipedia page on the topic I generally follow what's going on with the following code: :(){ :|:& };: excerpt of ...
13
votes
4answers
713 views

How to pass a password to a child process?

Passing a password on command line (to a child process started from my program) is known to be insecure (because it can be seen even by other users with ps command). Is it OK to pass it as an ...
12
votes
6answers
2k views

Why does “ls” require a separate process for executing?

Why does ls require a separate process for its execution? I know the reason why commands like cd can't be executed by forking mechanism but is there any harm if ls is executed without forking?
11
votes
4answers
5k views

How do fork and exec work?

I don't have much experience, just trying to get involved into the processes how do they interpret to hardware from user level. So when a command is fired from a shell, fork() inherits a child ...
11
votes
5answers
17k views

How to totally fork a shell command that is using redirection

I've written quite a few shell scripts over the years (but I'm certainly not a sysadmin) and there's something that always caused me troubles: how can I fork a shell command immune to hangups in the ...
11
votes
2answers
7k views

What's the difference between fork() and vfork()?

I would like to understand in detail the difference between fork() and vfork(). I was not able to digest the man page completely. I would also like to clarify one of my colleagues comment "In ...
11
votes
3answers
915 views

When a process forks is its virtual or resident memory copied?

The standard way of making new processes in Linux is that the memory footprint of the parent process is copied and that becomes the environment of the child process until execv is called. What memory ...
11
votes
1answer
212 views

Why do these bash fork bombs work differently and what is the significance of & in it?

I get how a normal fork bomb works, but I don't really understand why the & at the end of the common bash fork bomb is required and why these scripts behave differently: :(){ (:) | (:) }; : and ...
10
votes
4answers
4k views

Why should a child of a vfork or fork call _exit() instead of exit()?

From the man page of vfork(): vfork() differs from fork() in that the parent is suspended until the child makes a call to execve(2) or _exit(2). The child shares all memory with its parent,...
10
votes
3answers
20k views

Does bash support forking similar to C's fork()?

I have a script that I would like to fork at one point so two copies of the same script are running. For example, I would like the following bash script to exist: echo $$ do_fork() echo $$ If this ...
10
votes
5answers
4k views

Process descendants

I'm trying to build a process container. The container will trigger other programs. For example - a bash script that launches running background tasks with '&' usage. The important feature I'm ...
10
votes
1answer
290 views

How does ksh93 avoid forks in command substitution

Given cmd='fun(){ echo "$@"; }; fun $(fun $(fun hi))' shells tend to need to make 2 forks to make it happen strace-f(){ strace -f "$@" 2>&1; }; for sh in dash bash zsh ksh; do ...
8
votes
5answers
8k views

Threads vs (Forked) Processes

Linux applications generally fork then exec (with execve() ), but Java applications, and certain Apache MPMs use threading. If forking, uses the fork + exec to spawn a process, what is the high level ...
7
votes
2answers
11k views

How does copy-on-write in fork() handle multiple fork?

According to Wikipedia (which could be wrong) When a fork() system call is issued, a copy of all the pages corresponding to the parent process is created, loaded into a separate memory location by ...
7
votes
3answers
4k views

How to stop Fork Bomb out of memory error - RHEL 6

I set up test VM to test the effect of fork bombs. So I edited the limits.conf as follows for root user: root hard nproc 512 Now I drop a fork bomb like so: :(){ :|:& };: After ...
6
votes
3answers
2k views

Can I pipe any two processes to each other?

In this page from The Design and Implementation of the 4.4BSD Operating System, it is said that: A major difference between pipes and sockets is that pipes require a common parent process to set ...
5
votes
1answer
242 views

Why is the following command killing a system?

Anyone understand the following code , running in bash ? :(){ :|:& };: It seems to be a "fork" bomb on Linux.
5
votes
2answers
3k views

Fork call and recursion

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { fork(); fork(); fork(); puts("hi"); return 0; } This program ...
5
votes
2answers
1k views

Why do forked processes sometimes appear with brackets [] around their name in ps? [duplicate]

On a Linux system a C process is started on boot, which creates a fork of itself. It is not a kernal process or something. In most cases a ps -ef show both processes as expecxted, but sometimes it ...
5
votes
3answers
4k views

How to track the number of processes and forks per user?

I need to figure out how many forks are done and how many concurrent processes are run by each user over time. It does not look like this information is tracked by my distribution. I know how to ...
5
votes
2answers
12k views

fork: retry: Resource temporarily unavailable

While I am connecting to my server I get, -bash: fork: retry: Resource temporarily unavailable -bash: fork: retry: Resource temporarily unavailable -bash: fork: retry: Resource temporarily ...
5
votes
4answers
347 views

Coloring output of forked processes

I have a runscript that starts some processes and sends them to the background mongod & pid_mongo=$! redis-server & pid_redis=$! # etc. All these processes then output concurrently to ...
4
votes
2answers
5k views

File descriptor and fork

When a child is forked then it inherits parent's file descriptors, if child closes the file descriptor what will happen ? If child starts writing what shall happen to the file at the parent's end ? ...
4
votes
1answer
601 views

what does it mean 'fork()' will copy address space of original process

I'm studying 'operation system concepts' on my own and I'm studying the chp3. process part. There is an example where the 'fork()' function is called and depending of the returned pid value like the ...
4
votes
3answers
9k views

Fork bomb on a Mac?

I just learned about a fork bomb, an interesting type of a denial of service attack. Wikipedia (and a few other places) suggest using :(){ :|:& };: on UNIX machines to fork the process an infine ...
3
votes
3answers
3k views

Fork: Negative return value

From the fork(2) man page: RETURN VALUE On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is returned in the parent, no ...
3
votes
4answers
76 views

Who forks the processes of piped commands in the shell?

Consider this command in the shell : ls|less Now we know that ls and less are run as two different processes. We know that the shell forks and creates a child process which load the ls program using ...
3
votes
3answers
327 views

Dmenu Processes Forked by Bash?

I was looking at the output of pstree, and realised that processes that I started using dmenu seem to fork from bash. What is the reasoning behind this? And is there any way I can make dmenu behave ...
3
votes
3answers
4k views

What after exec() in ls command. Is the parent process printing the output to the console or the child?

I have a simple doubt on execution of the command ls. As per my understanding from the research I have done on the internet, I understood the below points. When we type ls command shell interprets ...
3
votes
2answers
2k views

What sets a child's STDERR, STDOUT, and STDIN?

If a program runs fork() what sets standard streams STDOUT, STDIN and STDERR?
3
votes
1answer
346 views

Get output of `posix_spawn`

So I can run a process in Unix / Linux using POSIX, but is there some way I can store / redirect both the STDOUT and STDERR of the process to a file? The spawn.h header contains a deceleration of ...
3
votes
1answer
3k views

fork() and how signals are delivered to processes

I program that I wrote in C fork()'s off a child process. Neither process will terminate. If I launch the program from the command line and press control-c which process(es) will receive the interrupt ...
3
votes
2answers
773 views

When vfork is called is parent process really suspended?

As much as I know when vfork is called child process uses the same address space as that of the parent and any changes made by the child process in parents variables are reflected onto parents process....
3
votes
1answer
205 views

COW and fork - how many frames

Consider process P that owns 10 physical frames. Suppose process P calls fork() and creates a child process Q. How many physical frames does the child initially own, without copy-on-write? 10 How ...
3
votes
1answer
75 views

GDB hangs forever on Solaris

GDB seems to hang everytime when I try run command from gdb prompt. When I ran ps, there are two gdb processes that have been spawned and pstack reveals the following - 15:47:02:/home/stufs1/...
3
votes
1answer
3k views

Program stall under user but runs under root

I am running R job under a normal user john and root. Interestingly, the program stalls under john user but runs quickly under root. Using strace, I found that when john runs the R, the process stalls ...
3
votes
1answer
81 views

How is the inherited file descritor vulnerability dealt with in Unices?

Ulrich Drepper describes a vulnerability in programs that have open file descriptors then they fork() and execve() without lots of very careful locking in place. He also talks about new kernel ...
2
votes
2answers
1k views

How to make processes not die after its parent dies?

I've been messing with forkbombs and noticed that if I just fork() processes repeatedly, killing the initial process will bring down the whole tree. This is not the case for forkbombs written in BASH ...
2
votes
2answers
146 views

How does bash pass user groups to a child?

It is well-known that if I add myself to a new group, that change will not be reflected until I log out and back in: $ sudo adduser me newgroup $ groups me sudo $ groups me me sudo newgroup $ This ...
2
votes
1answer
1k views

Which system calls could create a new process?

When executing ps command in my Linux system i see some user processes twice (different PID...). I wonder if they are new processes or threads of the same process. I know some functions in standard C ...
2
votes
1answer
736 views

How does bash actually change stdin/stdout/stderr when using redirection/piping

Unfortunately I've had no luck figuring this out, as everything I find is just on the syntax of redirection, or shallow information about how redirection works. What I want to know is how bash ...
2
votes
1answer
4k views

Apache cannot fork: cannot allocate memory

I am running apache on Fedora with mod_perl. The server forks a process to send an email frequently - and the fork exits. Suddenly, I got: Cannot fork: Cannot allocate memory. There was plenty of ...