Questions tagged [wait]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
67 views

Does POSIX sh require expanding $! in order to keep a reference to the child process?

Spec According to this online POSIX Spec, in Shell & Utilities, Shell Command Language, Section 2.9.3 Lists has the following to say about Asynchronous Lists: When an element of an asynchronous ...
D. Ben Knoble's user avatar
0 votes
1 answer
79 views

Is it possible to defer reaping of background processes in bash?

If I just run sleep 1 & in bash, the sleep process will get reaped almost instantly after it dies. This happens whether job control is enabled or disabled. Is there a way I can make bash hold off ...
Joseph Sible-Reinstate Monica's user avatar
2 votes
1 answer
503 views

using wait (bash posix) and fail if one process fails in a script

I am writing a script that executes a bunch of commands in the background all at once then waits for them to all finish: #!/bin/sh -fx ./p1 & ./p2 & ./p3 & ./p4 & ./p5 & wait The ...
user567972's user avatar
1 vote
2 answers
64 views

How to add file markers to check if script is already running

I wonder if I can get some help with a project I'm working on. I have a Synology NAS. I found a Community Package that autoruns a script of my creation anytime a USB drive is plugged in to one of the ...
Matt's user avatar
  • 13
1 vote
1 answer
6k views

Curl returning with no response and does not wait for `wait=x seconds`

I call an async service that takes ~80 seconds to respond. I run: curl -v -X POST https://hostname.com/service/v2/predict \ -H 'x-api-key: somekey' \ -H 'x-request-id: longfiles' \ -H "...
Franck Dernoncourt's user avatar
0 votes
0 answers
32 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 }
Alexander Mills's user avatar
0 votes
0 answers
166 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. ...
user183980's user avatar
1 vote
1 answer
225 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 "...
Zeta.Investigator's user avatar
7 votes
1 answer
640 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 ...
Saeed Neamati's user avatar
4 votes
2 answers
993 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", (...
shawdowfax1497's user avatar
2 votes
1 answer
797 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 ...
pigeon_gcc's user avatar
4 votes
2 answers
1k 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 ...
chengdol's user avatar
  • 163
0 votes
0 answers
276 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 ...
Logan Lee's user avatar
  • 249
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 ...
Fabian Röling's user avatar
5 votes
3 answers
9k 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? ...
Tim's user avatar
  • 100k
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 (...
adazem009's user avatar
  • 621
5 votes
1 answer
894 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 ####...
Amtrix's user avatar
  • 153
22 votes
1 answer
6k 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?
testter's user avatar
  • 1,370
0 votes
1 answer
501 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 ...
rplee's user avatar
  • 369
0 votes
0 answers
435 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 ...
Eduardo's user avatar
  • 101
4 votes
1 answer
2k 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 ...
Chris Stryczynski's user avatar
0 votes
1 answer
4k 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 ...
Regis Barbosa's user avatar
0 votes
1 answer
395 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,543
2 votes
1 answer
268 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 ...
Bodisha's user avatar
  • 151
0 votes
1 answer
2k 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("...
MP Creations's user avatar
0 votes
0 answers
427 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
2 answers
2k 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 & # ...
Leo's user avatar
  • 131
0 votes
0 answers
28 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 ...
user1192748's user avatar
2 votes
2 answers
566 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 ...
Vas's user avatar
  • 23
1 vote
1 answer
4k 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 ...
sburke's user avatar
  • 13
2 votes
1 answer
866 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. ...
Wilson Borba Neto's user avatar
2 votes
2 answers
296 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. ...
glarry's user avatar
  • 904
0 votes
1 answer
1k 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 ...
michael's user avatar
  • 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 ...
conste's user avatar
  • 131
3 votes
1 answer
966 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 ...
Whymarrh's user avatar
  • 175
2 votes
2 answers
8k 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 ...
Darshan L's user avatar
  • 259
1 vote
1 answer
714 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 ...
p4ndepravity's user avatar
8 votes
3 answers
9k 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+...
Hari Sundararajan's user avatar
0 votes
1 answer
152 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 ...
Tim's user avatar
  • 100k
0 votes
2 answers
2k 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 ...
RamenCoder's user avatar
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 ...
Prvt_Yadav's user avatar
  • 5,792
5 votes
1 answer
8k 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,$?>>$...
lovechillcool's user avatar
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 ...
Nani's user avatar
  • 343
2 votes
1 answer
839 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 ...
Alexander Mills's user avatar
38 votes
2 answers
64k 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 ...
user avatar