Questions tagged [fork]
The fork tag has no usage guidance.
150
questions
0
votes
1answer
30 views
Cgroup memory limits and process killing
I have the following situation: (The following functions are ones taken from python)
I have a process A which is running and has a cgroup memory limit set on it.
I fork a child process from A using ...
1
vote
1answer
43 views
Do subprocesses keep pipes open?
I am trying to understand the behaviour of programs that launch subprocesses, when run in a pipeline.
This bash program, fork.sh, prints and returns immediately:
(sleep 1) &
echo 'here'
But ...
0
votes
2answers
39 views
kill( ) won't stop subprocess if done from process started by /etc/rc.local?
On a raspberry pi (a recent raspian) I wrote an application that, on demand via network request, spawns an application, and on demand via different network request, kills it. The spawning mechanism is ...
0
votes
1answer
32 views
fork(), exec() sequence with object file formats?
It's my understanding that POSIX systems rely on certain linker formats to organize memory during a fork() exec() sequence of calls. a.out, COFF and ELF are widely known formats of binary object ...
0
votes
0answers
63 views
what's the execution sequence of multiple child processes
use the follwing code to fork four chile processes
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
pid_t pid;
int ...
0
votes
1answer
32 views
Difference between pid_max/ulimit. How to create fake processes?
I am trying to learn the nuances between pid_max and setting user limits through ulimit. My understanding is that, no matter how high you set the user limits (for example setting user max processes to ...
0
votes
0answers
25 views
How does this code execute more than one case of the if - else statements? [duplicate]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
printf("hello world (pid:%d)\n", (int) getpid());
int rc = fork();
if (rc < 0) {
// ...
1
vote
0answers
29 views
How can I create a function that memoizes other commands?
I have created the following function to memoize any command:
# zsh
(( $+functions[ec] )) || {
ec() print -r -- "$@"
ecerr() { ec "$@" 1>&2 }
ecdbg() ecerr "$@"
gq() { ec "${(q+...
15
votes
3answers
2k views
Why should fork() have been designed to return a file descriptor?
On his web page about the self-pipe trick, Dan Bernstein explains a race condition with select() and signals, offers a workaround and concludes that
Of course, the Right Thing would be to have fork(...
0
votes
1answer
195 views
How to create a process in Linux?
I am a research student working on an experiment involving Linux, and for it I need to create processes. I know how to create them with the fork() system call, but I was wondering if there was an ...
0
votes
0answers
32 views
Can a process group exist without a process group leader
Saying that I have two bash scripts as below:
#!/bin/bash
# this is test.sh
./test2.sh
and
#!/bin/bash
# this is test2.sh
while :
do
sleep 2
done
After executing the test.sh with the command ....
1
vote
2answers
57 views
Listen to a folder and modify incoming files on change
I want to convert pcap files to json files using shell script (and tshark). As soon as one or more new pcap files are copied into a folder, the command tshark should be executed and the resulting json ...
-1
votes
1answer
528 views
Two processes with identical PID after a fork call
According to the fork documentation (man 2 fork):
The child process is an exact duplicate of the parent process except for the following points:
The child has its own unique process ID, and ...
0
votes
0answers
216 views
systemd: process with fork() only shows logs after child exits
I have a program that fork()s and exits. Its child remains running for about 50 seconds, while it prints out messages each 5 seconds. When I run from a terminal it runs as expected, the parent exits, ...
3
votes
1answer
473 views
Why forking is used in a unit file of a service?
My nginx unitfile is following,
[root@arif ~]# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup....
0
votes
0answers
38 views
how to get the program and parent program of do_fork()
I'm trying to make a kernel module that would gather statistics about which process forks what subprocess. Kprobe seems like it might work, but I'm struggling to understand the structs that I get.
I ...
1
vote
1answer
149 views
Bash and Sudo forking continuously, hidden fork bomb?
I am experiencing a frustrating problem where my bash and sudo programs seem to be replicating thousands of processes on Mac. I have searched for all kinds of ways to stop them. I don't know what to ...
0
votes
2answers
446 views
Question about global environment variables and fork() & exec() [duplicate]
What I'm trying to understand is where does a child process inherit exported variables from it's parent process
What I'm trying to understand is where a child process inherits exported environment ...
0
votes
2answers
304 views
Would a forked child always get same File ID as parent's file ID?
This might be a naive question, but given in parent open call returned me File ID 4.
Is it guaranteed that child process will always get a File ID of 4 as well ?
0
votes
1answer
194 views
Why can't a fork bomb be killed in zsh in the same way as it's killed in bash?
I wanted to make my system a little bit more resilient to fork bombs. This can be partially achieved by using systemd's DefaultTasksMax parameter, or by using cgroup's pids controler for all valid ...
0
votes
2answers
1k 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 ...
0
votes
0answers
99 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/...
54
votes
3answers
12k 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
589 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
603 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
233 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
117 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
167 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
233 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 ?
51
votes
4answers
12k 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
190 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
747 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 ...
1
vote
2answers
157 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
94 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
1k 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 ...
1
vote
0answers
466 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
261 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
1k 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
256 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
521 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 ...
2
votes
2answers
2k 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
402 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 ...
3
votes
1answer
4k 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, ...
9
votes
4answers
4k views
When to call fork() and exec() by themselves?
I'm 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 current process image with a ...
1
vote
1answer
369 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
361 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
801 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
235 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
670 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
921 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,...