Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [fork]

The tag has no usage guidance.

0
votes
2answers
25 views

Is copy-on-write not implemented based on page fault?

Operating System Concepts say fork() we can use a technique known as copy-on-write, which works by allowing the parent and child processes initially to share the same pages. ... When it is ...
3
votes
0answers
41 views

waitpid() error problem [migrated]

I wrote code to print pid in order parent->g3->c2->g1->g2->c1. So I used wait(), and waitpid(). But I failed. So I wrote "finish"code to know what is problem. And I knew that c1 ...
0
votes
0answers
51 views

Measure memory usage of forked processes

In order to measure memory usage of a process, Iam using the VmPeak and VmSize fields of /proc/[pid]/status. What happens to memory reporting if this process is forked after allocating memory? My ...
0
votes
0answers
31 views

Listen for child process creation/fork

Say I have a process like so: #!/usr/bin/env bash node foo.js & pid=$! is there a way to listen to child processes that get created from pid? I want to create a list of pids that get created/...
52
votes
3answers
9k views

Why can't I crash my system with a fork bomb?

Recently I've been digging up information about processes in GNU/Linux and I met the infamous fork bomb : :(){ : | :& }; : Theoretically, it is supposed to duplicate itself infinitely until the ...
1
vote
1answer
119 views

fork() and COW behavior after exec()

We understand the COW behavior after a fork (as for example described here) as follows: fork creates a copy of the parent's page table for the child and marks the physical pages read only, so if any ...
1
vote
1answer
114 views

How to change working directory of a child process by posix_spawn? [closed]

In Linux (CentOS 7.5, kernel 3.10, gcc 7.3), is it possible to change the working directory of a child process created by posix_spawn before it runs a given process image (an executable)? If yes, how? ...
0
votes
0answers
90 views

can two running processes share the complete process image in physical memory, not just part of it?

can two running processes share the complete process image in physical memory, not just part of it? Here I am talking about the Linux operating systems(eg. Ubuntu). My thinking: I think it is ...
0
votes
0answers
64 views

AIX kernel internal stats of nmon: fork vs exec

Why the values of fork and exec stats shown on the kernel internal stats of nmon utility in AIX systems (k option) are so different? Usually the shown fork value is greater than the exec value, ...
0
votes
1answer
91 views

What happens if you fork before switch_root?

So typically an initramfs /init script will end with something like exec switch_root /newroot /sbin/init effectively replacing itself with systemd or whatever floats your boat. But what would happen ...
0
votes
1answer
86 views

Does a forked process copy all mapped memory when writing?

I understand that a forked process maps the parent's memory and copies it when writing to it. Does it copy just what it needs written or does it copy the entire mapped memory ?
43
votes
4answers
6k views

Why does a program with fork() sometimes print its output multiple times?

In Program 1 Hello world gets printed just once, but when I remove \n and run it (Program 2), the output gets printed 8 times. Can someone please explain me the significance of \n here and how it ...
1
vote
0answers
80 views

Is it possible to fork the current pane in tmux and put it in a new pane?

Often I have set up some temporary environment variables/modules and I would like them to persist as I create a split in Tmux. Is it possible to fork the current running program (i.e. bash) and put ...
0
votes
2answers
100 views

Physical Address of a variable in processes

When we create a child process by using the system call fork(), address space of parent process is copied to child process. The code below demonstrates this clearly. #include <stdio.h> #include ...
0
votes
2answers
54 views

Making a bind-mount take effect only in the context of the current process and its descendants

I have 2 files: /MyDir/a and /MyDir/MySubDir/b and am running a bash script, to which I want to add code to make file /a point to file /b, but only in the current process and its descendants. In ...
1
vote
2answers
79 views

Is it possible to findout if our command is sourced from a script or manually typed on command line?

We have an implementation to set environment for a particular tool with our custom command. Eg: custom_command tool_name This command logs the invokation time, user and tool_name in a log file. And ...
1
vote
1answer
295 views

Creating a specific process tree and terminating it

I am currently taking a Computer Systems class and am having trouble with a homework problem. I have to create this specific process tree: I also need it to stay in this state for a while (using ...
0
votes
0answers
268 views

Why did ulimit not stop my fork bomb that was running as the superuser?

I'm studying the fork bombs and I have some troubles to find a way to protect from this type of attack. As far as I know there are two possible solutions: ulimit cgroup I'm studying the first one on ...
0
votes
0answers
101 views

Creating an exact copy of a whole process?

fork() forks a process, but it will not copy all of its threads; nor will it create a clone of all its fds: the fds are shared between parent and child. I want a way of do a complete fork. So after I ...
1
vote
2answers
372 views

Why is the shell not waiting for a child process of a command after the command exits?

I have been learning about UNIX processes and could not understand one point. Say we have code like this, void fork_child() { if (fork() == 0) { /* Child */ printf("Running Child, ...
1
vote
0answers
153 views

How to configure new RSS value to a process in Linux 3.10?

I want to limit the RSS of my python process to 5GB. The python process is running C++ code in every iteration (there are 10000 such iterations) and executing some commands which interact with the C++ ...
-1
votes
2answers
272 views

fork() and execve() efficiency [closed]

In terms of memory allocation efficiency is it right to say that after a fork() in the code of the child if I execute a program with execve() this would be more efficient than the same program ...
1
vote
2answers
536 views

Why are file descriptors shared between forked processes?

When we fork() a process, the child process inherits the file descriptors. The question is, why? As I am seeing it, sharing the file descriptor is a headache when every process is trying to keep ...
1
vote
1answer
176 views

Linux open() syscall and folder permissions

I have a process P which is spawned by a process owned by root. After P is created setguid() and setuid() are called and it runs as user U. The process P attempts to create a file f on a folder F (in ...
1
vote
1answer
1k views

Systemd timeout because it doesn't detect daemon forking

I'm currently developping a systemd daemon. The problem I'm facing is that the daemon is killed 1m30s after beeing launched because the forking is not detected. I'm using the int daemon(int nochdir, ...
8
votes
4answers
2k views

When to call fork() and exec() by themselves?

I'm new to Unix system calls and am learning about fork() and exec() commands. It seems like fork() and exec() are usually called together. (fork() creates a new child process, and exec() replaces the ...
1
vote
1answer
208 views

how does pte's flags are restored when a page is swapped in from swap-area?

I would like to understand properly the swapping in process and yet, couldn't find a thorough explanation how pte's flags of a page are restored once a page is swapped in back to memory- since it's ...
0
votes
1answer
215 views

Yad forking and return results

I'm trying to make a yad process collaborate with another (a mounter but that's not very important). I have a code structure like this (simplified) in the critical part: ` yad --list --button=gtk-...
0
votes
1answer
312 views

How does a parent process know the process IDs of the child processes it started?

The title was a question in an exam I had recently. I could not find the answer afterwards in the slides (also not on the web). In the course slides it is only described that the parent process holds ...
-1
votes
1answer
145 views

What exactly is the function piping into the other function in this fork bomb :(){ :|: & };:?

There are a couple of questions related to the fork bomb for bash :(){ :|: & };: , but when I checked the answers I still could not figure out what the exactly the part of the bomb is doing when ...
1
vote
1answer
455 views

:(){:|:&};: How does this BASH fork bomb work in detail? [duplicate]

I have a very fragmentary understanding of shells, subshells, functions, background processes and therefore I am insecure in understanding how this fork bomb works in detail, However I tell you how ...
3
votes
2answers
531 views

Prevent a shell fork from living longer than its initiator?

If I have a Bash script like: function repeat { while :; do echo repeating; sleep 1 done } repeat & echo running once running once is printed once but repeat's fork lives forever,...
3
votes
1answer
775 views

shell script process fork

I am doing some experiments to know how environment variables are inherited from parent process to child process by executing shell scripts in zsh and then use pstree <username> to see the ...
3
votes
2answers
3k views

Why does fork sometimes return parent and sometimes child?

When running the fork call to create a new process, if it succeed it returns either 0 (the child) or the parent. I didn't get the idea behind this. Why doesn't fork just always return child or always ...
0
votes
0answers
271 views

How do you send stdout to the journal when using a process type of forking

I have a custom systemd unit file that uses the Type of forking. The initial process's stdout will be logged to the journal but the forked process's stdout is not logged to the journal. How can the ...
1
vote
1answer
615 views

docker fork/exec /proc/self/exe: cannot allocate memory

After a few days, docker fails with errors docker[8927]: level=error msg="Error running exec in container: execcantrun: Cannot run exec command 34a26 in container 4972e576: [8] System error: fork/...
3
votes
2answers
427 views

Systemd restart service if one of the processes in the control group fails

I have a systemd service unit: [Unit] After=network.target [Service] User=<user> Type=forking ExecStart=/opt/app/start.sh Restart=on-failure [Install] WantedBy=multi-user.target The /opt/app/...
3
votes
1answer
715 views

How does fork system call really works

I've a very specific question about fork system call. I've this piece of code: int main (void) { for (int i = 0; i < 10; i++) { pid_t pid = fork (); if ( !pid ) { ...
1
vote
0answers
477 views

Tracing a fork bomb

I am currently having an issue with a server running CentOS 6. For the past two days around midday we run into what I believe is one of our applications fork bombing the server. We start getting the ...
1
vote
1answer
175 views

When exactly does context_switch() switch control to a new process?

If I understand context switching correctly, the process involves two major steps: The MMU is switched to one that maps the new processes virtual memory space to physical memory space. The processor ...
-1
votes
1answer
83 views

Redirection in self created linux shell [closed]

I am writing my own shell. I want to implement redirection( > and >>). For that I have used dup2() system call. But if a command I enter has redirection, another command follows the previous ...
15
votes
1answer
2k views

How exactly does the typical shell “fork bomb” call itself twice?

After going through the famous Fork Bomb questions on Askubuntu and many other Stack Exchange sites, I don't quite understand what everyone is saying like it's obvious. Many answers (Best example) ...
3
votes
1answer
300 views

Unexpected parent process id in output

My code is forking a process and printing each process' PID and PPID. I was expecting the child's PPID to be same as the parent's PID, but it is not coming up as such. I'm using Ubuntu 14.04. #...
3
votes
1answer
305 views

Confused by this fork bomb script [duplicate]

There's a shell script floating around the Internet that looks like this: :(){ :|: & };: Basically this shell script just creates a function that calls itself, leading to infinite recursion. ...
1
vote
1answer
3k views

wrapper script: fork: retry: No child processes

"myapplication" needs some setup or clean up done, so I use the following wrapper script: #!/bin/bash echo "Do important set up stuff" myapplication echo "Clean up" and put it in my path, named "...
16
votes
4answers
2k 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 ...
3
votes
0answers
301 views

Theoric: How to kill a forever forking process?

Let's say you have a process that forks every time it has the chance. It launches itself in niceness -20, so it forks faster than you can kill it. Also, it remembers its childrens and it parents, so ...
12
votes
1answer
474 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 printf ...
3
votes
2answers
6k views

Putting subshell in background vs putting command in background

I have two bash scripts that try to check hosts that are up: Script 1: #!/bin/bash for ip in {1..254}; do ping -c 1 192.168.1.$ip | grep "bytes from" | cut -d" " -f 4 | cut -d ":" -f 1 & ...
-1
votes
2answers
357 views

Does the Ubuntu Linux 16.04 daemon function execute a double fork? [closed]

Does the Ubuntu Linux 16.04 daemon function execute a double fork? If so, why is a double fork necessary? [EDIT May 30 2016 8:11 AM] This is the official Linux Foundation source code for the daemon ...