Questions tagged [wait]

The tag has no usage guidance.

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

block in bash so that no more than 5 child processes are running at a time?

Is there a way to block in bash, something like this: function do_work { wait -c 5 ### wait until 5 or fewer cp's are running now do whatever else you wanted }
0 votes
0 answers
68 views

Bash script logging not working as expected with rsync jump server

I'm using a shell script below for doing some rsync on a remote host. By ssh to jumphost and from there ssh again and initiating the rsync as below. Here I need to capture the log start and end date. ...
1 vote
1 answer
77 views

How to kill all background and spawned processes of a bash script in its pre-exit handler?

I'm using the wait -n technique to perform max_jobs parallel tasks: #!/usr/bin/env bash cleanup() { echo "cleaning up..." } trap "cleanup" EXIT do_task() { echo "...
7 votes
1 answer
501 views

Why wait in this script is not executed after all subshells?

In this script, that pulls all git repositories: #!/bin/bash find / -type d -name .git 2>/dev/null | while read gitFolder; do if [[ $gitFolder == *"/Temp/"* ]]; then ...
4 votes
2 answers
502 views

Why or how does killing the parent process clean the zombie child processes in linux?

Consider this example - #include<stdio.h> #include<stdlib.h> #include<unistd.h> int main() { pid_t pid = fork(); if (pid > 0) { printf("Child pid is %d\n", (...
1 vote
1 answer
231 views

Why doesn't the 2nd command wait for the output of the 1st (piping)?

I'm currently reading M. Bach's "THE DESIGN OF THE UNIX® OPERATING SYSTEM". I read about the main shell loop. Look at the if (/* piping */) block. If I understood correctly, piping allows ...
3 votes
2 answers
511 views

zombie process reap without "wait"

I know if a subprocess does not get reaped properly, it will become a zombie and you can see it by ps command. Also the "wait [pid]" command will wait for subshell running on the background ...
  • 105
0 votes
0 answers
121 views

Closing stdout required for wait on sub process to finish?

I have a question from https://mywiki.wooledge.org/BashFAQ/106 Have a look at this code: exec > >(tee myfile) pspid=$! # ... stuff ... echo "A" cat file echo "B" # end stuff ...
  • 247
0 votes
2 answers
42 views

Will "$!" reliably return the correct ID with "&"?

In my tests, I always get the correct result so far with this: [fabian@manjaro ~]$ sleep 10 & echo $! [1] 302657 302657 But sleep and echo are getting executed simultaneously here, so I would ...
2 votes
3 answers
5k views

What is the relation between SIGCHLD and `waitpid()` or`wait()`?

If I am correct, a process waits for its children to terminate or stop by calling the waitpid() or wait() function. What is the relation between SIGCHLD signal and the waitpid() orwait() functions? ...
  • 92.7k
9 votes
1 answer
2k views

Press SPACE to continue (not ENTER)

I know this question has been already asked & answered, but the solution I found listens for space and enter: while [ "$key" != '' ]; do read -n1 -s -r key done Is there a way (...
  • 601
3 votes
1 answer
343 views

Why is the wait $pid command interrupted by any signal to the waiting process?

I can't find any documentation that explains my observations in sufficiently enough terms. After I run the below code, I perform a kill -SIGINT $my_pid from a different shell. I will correctly see ####...
  • 133
19 votes
1 answer
4k views

When and why do we need the `wait` command on bash?

Doesn't the bash shell already run the commands one by one and wait for the executed command to finish? So when and why do we need the wait command?
  • 1,132
0 votes
1 answer
323 views

Bash function that will wait for a process to be finished before starting a new one

I'd like to create a function that will wait until a job is completed before starting a new process. I'm aware of the wait command that is built into bash, but it only works for child processes. It ...
  • 359
0 votes
0 answers
245 views

Does wait work without SIGCHLD?

I have a parent process that runs a child process and then wait for it: myprocess & wait $! However, when myprocess exits, the parent process continues waiting for it. After listing the signals ...
  • 101
4 votes
1 answer
961 views

What determines whether a script's background processes get a terminal's SIGINT signal?

#!/usr/bin/env bash sleep 3 && echo '123' & sleep 3 && echo '456' & sleep 3 && echo '999' & If I run this, and send SIGINT by pressing control-c via terminal, it ...
0 votes
1 answer
2k views

Press ENTER to continue

I want to know if there is any way to make my script stop until the user hits the Enter key, but without using the command read, just by the options of stty. I was wondering a code for this and got ...
0 votes
1 answer
266 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.). ...
  • 1,335
2 votes
1 answer
229 views

Question about a process lifecycle

I've managed to question myself about the wait(2) and _exit(2) system calls in a process lifecycle. My question about the wait(2) system call is... does the parent process issue it to the kernel? Or ...
  • 131
0 votes
1 answer
1k views

Why SIGCHLD signal was not ignored when using wait() functions?

When using wait functions the SIGCHLD signal was consumed by wait when executing sample 1.1 as shown below. sample 1.1 if (pid==0){ printf("child\n"); printf("%d\n",pid); } else{ printf("...
0 votes
0 answers
256 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 ...
  • 103
0 votes
2 answers
1k views

`wait` for processes started in a for loop, but not others started earlier

Suppose I have several running background tasks, but now I want to run two more background tasks, but wait only for the last two. For example: # long running commands sleep 60 & sleep 60 & # ...
  • 131
0 votes
0 answers
24 views

Red Hat: Back-Off time during failed authentication attempts

I am searching for a way to configure some sort of back-off or wait time during failed authentication attempts. The idea is that after each failed authentication attempt, the user has to wait an ...
2 votes
2 answers
390 views

queue-like behaviour for multiple one-core jobs on single machine? [duplicate]

I've got an old Mac with 24 cores, and I'd like to run several hundred/thousands one-core jobs automatically. I've made a bash script that runs the processes in the background, but if I set too many ...
  • 23
1 vote
1 answer
3k views

Script hanging when using tee and wait, why?

I'm running a script which automates snapraid for my NAS server. It's a script I found online and it was working without issue on Debian 9. I updated to Debian 10 last week and the script now hangs in ...
  • 13
3 votes
1 answer
650 views

Kill the child process in a child xterm but not xterm

I'm new to Linux. I have python scripts in different files, each one performing a desired function. foo1.py foo2.py foo3.py Each one of these scripts should do cleanup before being terminated. ...
3 votes
2 answers
224 views

Regain ability to use ^C to close backgrounded then (effectively) foregrounded processes

In the interactive console, pressing ^C on zenity --info & fg closes the Zenity window. One can only use zenity --info & wait in a script. But ^C doesn't close the Zenity window in this case. ...
  • 884
0 votes
1 answer
967 views

how signals are handled in linux kernel [closed]

My question is about signals and handling them inside the operating system kernel. I know that every process has it own signal_handler() table: a 31 bit array for signals (pending_signals), and when a ...
  • 103
1 vote
0 answers
2k views

How to wait for the execution of a python script inside shell script?

I want to mount another root partition, edit the grub.cfg file with a python script and afterwards umount the partition again. How can I wait for the python script to finish and check if the partition ...
  • 131
3 votes
1 answer
685 views

What does the `-f' option do for `wait' versus the default behaviour?

Bash 5.0 includes a new -f option for wait:[1] j. The `wait' builtin now has a `-f' option, which signfies to wait until the specified job or process terminates, instead of waiting until it ...
  • 175
1 vote
2 answers
6k views

Why should parent process wait (to terminate) until all of its child process terminates?

I know there is no enforcement for the parent process to wait until all its child process terminates. However it's a convention followed. Furthermore, I know that if parent process terminates before ...
  • 215
1 vote
1 answer
576 views

tmux send-keys confirm ssh tunnel is closed (after sending multiple commands to the remote host) before proceeding

there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be ...
9 votes
3 answers
6k views

sleep, wait and Ctrl+C propagation

If I have the following shell script sleep 30s And I hit Ctrl+C when the shell script is running, the sleep dies with it. If I have the following shell script sleep 30s & wait And I hit Ctrl+...
0 votes
1 answer
128 views

How can I make `enscript` block till the printer finishes its job?

The following command will create a pdf file under ~/PDF/: enscript -B -P PDF bloom.c I want to move the output pdf file here ...
  • 92.7k
0 votes
2 answers
1k views

Wait command works when pid doesn't exists

I'm facing an unexpected behaviour of the wait builtin. ~ ❯ sleep 1 & [1] 72009 ~ ❯ [1] + 72009 done sleep 1 ~ ❯ wait 72009 ~ ❯ echo $? 0 Although the PID doesn't exist anymore wait ...
0 votes
2 answers
1k views

Use waitpid for child having groupid 1

I searched a lot but didn't find a solution. So it can be silly question. The format of waitpid is pid_t waitpid (pid_t pid, int *status, int options) The pid parameter specifies exactly which ...
  • 5,464
4 votes
1 answer
7k views

How do I wait for nohup jobs to finish within a shell script?

I have the following script: echo "$wk" | while read -r a b; do counter=$(($counter+1)) nohup sh -c 'impala-shell -d nielsen -f query.sql --var=dt=$a --var=incre=$b; echo $a,$?>>$...
2 votes
3 answers
2k views

Bash script to wait for a process to finish on multiple servers [duplicate]

I wanted to ssh to multiple servers remotely and check whether any processes running on those servers and wait until the process to get finished. I have written the below code but this checks only for ...
  • 333
2 votes
1 answer
686 views

Run subshells in parallel and collect exit codes

I have the following, I thought it ran the subshells in parallel, but it actually seems to run them in series, and I cannot figure out why: #!/usr/bin/env bash set -e; set -m # allow for job control ...
29 votes
2 answers
56k views

Run commands in parallel and wait for one group of commands to finish before starting the next

I have script including multiple commands. How can I group commands to run together ( I want to make several groups of commands. Within each group, the commands should run in parallel (at the same ...
's user avatar