Do you want to run a Linux or Unix/macOS program directly after some other process has ended? Use the pwait as follows:
```pwait pid && new_app1```
For example, for demo run sleep for 1200 and wait to end and then run the app2:
```sleep 1200 &
pwait pid_of_sleep_here && app2```
See the `pwait` man page for more info as syntax changes slightly between Linux and BSD version. This is very handy utility and not well known to many:
`man pwait`
![a screenshot of the pwait manual page from Linux. The screenshot reads:
NAME
pwait โ wait for processes to terminate
SYNOPSIS
pwait [-v] [-c] pid ...
DESCRIPTION
pwait waits until each of the given processes has terminated.
The options are as follows:
-v Print the exit status when each process terminates.
-c Return 111 if any process exited non-successfully.
EXIT STATUS
The pwait utility exits 0 on success, and >0 if an error occurs.
Invalid pids elicit a warning message but are otherwise ignored.
ERRORS
Check these prerequisites if you see this error:
binding sk_nl error: Operation not permitted
pwait requires special permissions to run, either root or the Linux CAP_NET_ADMIN capability.
pwait only works on Linux kernels with the kernel options
CONFIG_CONNECTOR=y
CONFIG_PROC_EVENTS=y](https://files.mastodon.social/media_attachments/files/115/690/335/506/213/092/original/a6d107c3beda2c78.png)