Questions tagged [wait]

45 questions
36
votes
2 answers

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 time). The groups should run sequentially, waiting…
user88036
22
votes
1 answer

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
  • 1,290
  • 2
  • 11
  • 24
9
votes
1 answer

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 (in bash) to make a script that will wait only for the space…
adazem009
  • 611
  • 1
  • 6
  • 10
8
votes
3 answers

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+C when the shell script is running, the sleep continues…
7
votes
1 answer

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 continue; fi if [[ $gitFolder == *"/Trash/"* ]]; then …
Saeed Neamati
  • 537
  • 4
  • 17
5
votes
3 answers

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? Is it correct that when a process calls the…
Tim
  • 98,580
  • 191
  • 570
  • 977
5
votes
1 answer

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,$?>>$week_status_file; if [ $? -ne 0 ]; then echo…
lovechillcool
  • 183
  • 1
  • 8
4
votes
2 answers

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

Consider this example - #include #include #include int main() { pid_t pid = fork(); if (pid > 0) { printf("Child pid is %d\n", (int)pid); sleep(10); system("ps -ef | grep defunct | grep -v grep"); } …
4
votes
2 answers

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 until it finishes and reap it. I have a script like…
chengdol
  • 155
  • 1
  • 6
4
votes
1 answer

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 #### received trap 2 the first two times. However,…
Amtrix
  • 143
  • 3
4
votes
1 answer

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 seems to still echo the 123... output. I assumed this is because it's somehow…
Chris Stryczynski
  • 5,178
  • 5
  • 40
  • 80
3
votes
1 answer

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 changes state. What does wait -f $pid do as opposed…
Whymarrh
  • 175
  • 1
  • 2
  • 10
2
votes
1 answer

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 problem is that if one or more of these processes fail, it just keeps…
user567972
  • 21
  • 1
2
votes
1 answer

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 treating the 1st command output as the 2nd command input. If…
pigeon_gcc
  • 39
  • 5
2
votes
1 answer

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 does the kernel issue it to the parent process?…
Bodisha
  • 141
  • 3
  • 9
1
2 3