Questions tagged [fork]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
40 views

fork() is very slow

I have a Linux server running Ubuntu 18.04 on a VM. Executing any task like ls -l or w frequently takes several seconds to finish. strace -c ls -l says ls only takes a few milliseconds, but running ...
Call of Guitar's user avatar
4 votes
0 answers
45 views

Perl's `kill` is using `$! == Errno::EINTR` unexpectedly

I wrote a network daemon that forks off children to handle TCP connections. On SIGINT the main process triggers a kill for each child in order to clean up and to collect some final statistics. In ...
U. Windl's user avatar
  • 1,397
0 votes
0 answers
51 views

Forking from a systemd service [duplicate]

I have a python program that runs as a systemd user service. From that program, I launch external commands via subprocess.Popen(cmd, close_fds=True, start_new_session=True). My intention is for these ...
czert's user avatar
  • 1
0 votes
1 answer
94 views

What's the difference between "-dm" and "-Dm" in GNU Screen?

The GNU Screen manual says: `-d -m' Start `screen' in _detached mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts. ...
Sebastian Carlos's user avatar
1 vote
2 answers
1k views

What is the "correct" way to run a systemd service which spawns long running detached processes?

I have a systemd service which spawns an ffmpeg process any time it detects a new event. These processes are meant to survive and run to completion even if the service is restarted (hence them being ...
plunker's user avatar
  • 77
1 vote
1 answer
101 views

Child and sibling processes from running tmux in zsh

I am using Ubuntu 22.04.1 on WSL 2 (though the fact that it is Unix is only relevant for this question) How come when we run tmux from a zsh session, the process tree (which I have abridged somewhat) ...
Abced Decba's user avatar
1 vote
1 answer
114 views

What is the easiest way to run a VM that executes a simple C program

I'm trying to run a simple one file C program in a Virtual Machine. In fact it is the fork bomb c program: #include <stdio.h> #include <sys/types.h> int main() { while(1) { ...
someone12321's user avatar
0 votes
1 answer
75 views

I'm curious about the difference between running a daemon with a systemctl command and running it directly [duplicate]

I had a question while dealing with the issue related to snmp in my project. If you enter the following command to execute snmpd with various options, snmpd will be executed without any problem. $ ...
monster-dev's user avatar
0 votes
0 answers
1k views

fork: Resource temporarily unavailable - on CentOS server

I can't run anything anymore (hardly anything) and I keep getting the following error message. If I execute a command, it can be it comes several times the error fork: retry: No child processes, if I ...
phanaz's user avatar
  • 169
17 votes
1 answer
5k views

Double fork() - why?

I found the following function in the source code of catwm (a minimalistic window manager): void spawn(const Arg arg) { if(fork() == 0) { if(fork() == 0) { if(dis) ...
Alex's user avatar
  • 351
0 votes
2 answers
299 views

Fork stdin to stdout & stderr?

I am wondering if it's possible to fork standard input to stdout & stderr? Something like this, $ echo "hi" | fork > std.out 2> std.err $ cat std.out hi $ cat std.err hi Or, am I ...
David Streid's user avatar
1 vote
0 answers
47 views

Is the stack of a forked process shared with its parent? [duplicate]

Is the stack of a forked process shared with its parent? If so, does this happen via shared copy-on-write pages?
HappyFace's user avatar
  • 1,613
0 votes
0 answers
133 views

Why are my forked processes being killed?

I'm running on a Red Hat RHEL 7.9 server. I have a Perl script which repeatedly calls fork() to run several hundred different small C-based programs. It only runs about 10 programs at a time (my ...
JB_User's user avatar
  • 363
4 votes
1 answer
2k views

How does the fork system call work?

If we look at the example #include <stdio.h> #include <unistd.h> void main(){ int pi_d ; int pid ; pi_d = fork(); if(pi_d == 0){ printf("Child Process B:\npid :%d\nppid:%...
Lkaf Temravet's user avatar
1 vote
1 answer
658 views

tell socat to stop on connection refuse with fork enabled

I'm using this instruction to forward a port to another, both on a local machine: socat -d -d TCP4-LISTEN:80,reuseaddr,fork TCP4:127.0.0.1:8000 I need to keep the port open unless the destination ...
Little Apocrypha's user avatar
1 vote
1 answer
5k views

How does a process and its children use memory in case of mmap()?

Let's say, we are creating a shared memory using mmap(). Let's say the total memory size is 4096. If we use a fork() system call to create children, would the children use the same memory, or will ...
unixgeek's user avatar
0 votes
1 answer
130 views

Practically unfork process

I have an executable binary (no source) that clone()s. It doesn't print anything and I think the child is trying to, which I'd like it to do. It always returns successfully even when the child ...
sedwho's user avatar
  • 5
0 votes
1 answer
518 views

how fork() can return multiple values? [duplicate]

How does the fork() function return different values in parent process and child process? Assume there is no write operation in parent process and its child process.
Abdullah's user avatar
1 vote
1 answer
976 views

Command, args and process name

I learned recently of pidof, and I was comparing it to pgrep. While doing that, I noticed that pidof returned several PIDs for Firefox, while pgrep returned just one. I checked pgrep's man page and ...
caxcaxcoatl's user avatar
1 vote
0 answers
118 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 ...
KiralyCraft's user avatar
0 votes
1 answer
927 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 ...
Le Ray's user avatar
  • 103
1 vote
2 answers
903 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 ...
doden's user avatar
  • 11
0 votes
1 answer
113 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 ...
istepaniuk's user avatar
1 vote
0 answers
929 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, ...
Synthaze's user avatar
  • 111
1 vote
1 answer
446 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 ...
Sally Beuford's user avatar
0 votes
1 answer
526 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() { ...
Dacaramo's user avatar
0 votes
2 answers
865 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 ...
darthDoe's user avatar
1 vote
1 answer
450 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, ...
testter's user avatar
  • 1,400
0 votes
1 answer
138 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 ...
aderchox's user avatar
  • 681
14 votes
2 answers
6k 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 ...
chesnutcase's user avatar
2 votes
1 answer
575 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, ...
Arqwer's user avatar
  • 528
1 vote
1 answer
242 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 ...
Paralyz3d's user avatar
  • 147
0 votes
0 answers
23 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 ...
spraff's user avatar
  • 911
1 vote
1 answer
393 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 ...
Don Foumare's user avatar
0 votes
1 answer
435 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.). ...
HappyFace's user avatar
  • 1,613
0 votes
0 answers
450 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 ...
Max's user avatar
  • 103
0 votes
1 answer
361 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 ...
Hogfeldt's user avatar
  • 196
2 votes
0 answers
95 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 ...
iBug's user avatar
  • 3,498
0 votes
0 answers
54 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 ...
Shuzheng's user avatar
  • 4,283
1 vote
1 answer
9k 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 ...
likecs's user avatar
  • 113
1 vote
1 answer
347 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 ...
reentim's user avatar
  • 13
0 votes
2 answers
524 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 ...
Scott M's user avatar
  • 355
0 votes
1 answer
137 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 ...
Nick's user avatar
  • 195
0 votes
1 answer
260 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 ...
Alexander D's user avatar
1 vote
0 answers
79 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+...
HappyFace's user avatar
  • 1,613
15 votes
4 answers
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(...
Lassi's user avatar
  • 831
0 votes
1 answer
2k 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 ...
Ramsey Alsheikh's user avatar
1 vote
2 answers
183 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 ...
mudvayne's user avatar
-2 votes
1 answer
3k 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 ...
ABu's user avatar
  • 556
2 votes
0 answers
1k 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, ...
Adriano_epifas's user avatar