Questions tagged [fork]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
0answers
37 views

Accidental C Fork Bomb - Keeps forking after being killed

I am in charge of a CentOS 7 server running kernel 2.6.32 which is used for people to learn the basics of C under Linux, which unfortunately includes fork(). Sometimes honest accidents happen, where a ...
0
votes
1answer
35 views

Why is 'ls' being created by execve() call and not fork()

From my understanding whenever you type a command such as 'ls' in your shell, the parent process which is my shell duplicates itself using fork() system call and then uses the exec() system call to ...
0
votes
2answers
105 views

how to create a pipe forks two processes

could anyone help me in understanding what does this question requires? and the steps to do it? "Write a simple program that creates a pipe forks two processes and then sends data through the ...
0
votes
0answers
16 views

Timer disarms when interval is too small

Timers seem to disarm after process is resumed (SIGCONT) ONLY when interval is too small. I use timer_create with CLOCK_REALTIME. My linux distribution is ubuntu 20.04.1 This is the code that shows ...
1
vote
1answer
43 views

How can I have the PIDs in the systemd journal for proecesses that share the standard output file descriptor?

When a process fork()s children without closing and reopening standard IO, all children share the same IO file descriptors. By default, running such forking process in a systemd unit will result in ...
1
vote
0answers
159 views

Failed to fork (Cannot allocate memory) gnome-terminal

Running on Debian 10, gnome 3.30.2, I am getting for two days memory errors when trying to open new terminals after some time during the session. Reboot does not fix it fore more than a few hours, ...
1
vote
1answer
48 views

Is there a better method than ptrace for intercepting (“catching”) Linux syscalls coming from a forked process?

I would like to catch all syscalls coming from a forked process, modify them, send them to the kernel, and then pass them back to the forked process. Is this possible, and if so, how might I go about ...
-1
votes
1answer
26 views

Send signal to paused parent process and guarantee that it will arrive AFTER the parent pauses

I have this kind of pseudo-code and i'm wishing to know what I must change in order to guarantee that the signal send to the parent will indeed arrive after that the parent pauses. int main() { ...
0
votes
2answers
169 views

Does fork() also copy the file descriptor for the executable binary that the calling process is currently executing?

I've read the man pages on fork(), and they say something along the lines of "all file descriptors open in the calling process are copied". It is not 100% clear to me if the file descriptor ...
1
vote
1answer
56 views

How exactly do programs or bash shell commands work on Linux systems?

I am researching how processes and shell work in Linux system. I would like to consult you to see if my conclusions are correct. When we start the system, the kernel starts the init process, ...
0
votes
1answer
42 views

Three Questions on Child Shells: Lifespan and Creation

Is a child shell's life over shortly after it's created? I.e., do its assets get replaced by the process that is going to be run in it? Say we've run grep -r "something" in bash, so our ...
13
votes
2answers
2k views

Why “the process must not fork” for simple type services in systemd?

I want to write my own systemd unit files to manage really long running commands1 (in the order of hours). While looking the ArchWiki article on systemd, it says the following regarding choosing a ...
1
vote
1answer
91 views

Can I force some process to execute fork system call, from outside of that process?

Let's say there is a program, that waits for user input. If user input is "A", program goes to state s_a, and if user input is "B", program goes to state s_b. I don't know which state I need, ...
1
vote
1answer
113 views

How can I use fork to calculate partial results of a calculation?

The task that has been given to me is that I have to find all numbers that divide a number (let's call it x) and find out how many times does it divide it. I have to use fork to do the task. What I ...
0
votes
0answers
12 views

Can I efficiently fork a ramfs partition?

I want a ramfs (or equivalent, but strictly RAM only) partition which will serve as a read-only master instance from which any number of identical children can be forked. When a process forks, this ...
1
vote
1answer
66 views

Recurrent output of printf() to stdout each time fork() is invoked allthough printf() is invoked prior to fork(). And why does '\n' fixes this? [duplicate]

While I was playing around with fork() I noticed a rather strange behavior but I couldn't figure out myself why this happens. In the example below, each time fork() is invoked the output from the ...
0
votes
1answer
88 views

Can I wait for all forked processes from a command to finish?

Suppose running FOO stars BAR in the background. How can I wait for BAR to finish in the shell? I want a solution where I don’t change the internals of FOO (though I can grudgingly change BAR’s.). ...
0
votes
0answers
73 views

Receiving SIGKILL when children terminate

I want to receive SIGKILL instead of SIGCHLD when any of my forked children terminate. On Linux this is possible by passing a different child termination signal to clone()1. Is this possible on any ...
0
votes
1answer
130 views

Interacting programs stdin and stdout (create a robot program to play a game)

The setup: I have an executable file, that I "cannot edit", since I don't have the source code. When I execute the program it reveals a game, where it hands me some numbers via stdout, for me to ...
2
votes
0answers
44 views

Make Linux reboot when it runs out of PID

I want to configure a headless server to automatically reboot under catastrophic circumstances. Right now I have configured to make it panic when running out of RAM, and reboot automatically on kernel ...
0
votes
0answers
48 views

Why is “&” necessary to make a Unix fork bomb work? [duplicate]

Consider the canonical example of a Unix fork bomb: DANGER: running the following command, might crash your system. :(){ :|: & };: I wonder why & (background) is needed in order to use up ...
1
vote
1answer
2k 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
86 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
305 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
63 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
494 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
111 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 ...
1
vote
0answers
47 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+...
16
votes
4answers
3k 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
1k 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 ...
1
vote
2answers
108 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
1k 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 this PID ...
1
vote
0answers
565 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, ...
4
votes
2answers
2k 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
87 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
299 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
2k 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
711 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
452 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
3k 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
139 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/...
57
votes
3answers
14k 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
1k 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 ...
2
votes
1answer
1k 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
429 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
155 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
246 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
2answers
645 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 ?
57
votes
4answers
19k 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 ...
2
votes
0answers
290 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 ...