Fix Could Not Fork Child Process Terminal Error

The “no available terminals” error means the terminal application could not obtain a usable pseudo-terminal for its new shell. In Cygwin and Git Bash, start by closing unused sessions and stopping confirmed leftover SSH-related processes, then reopen the terminal. Use the exact error wording and when it appears to choose the right troubleshooting path.

Symptom Likely Cause or Diagnostic Lead What to Do
“No available terminals” appears after using SSH or Pageant integration A surviving SSH client or helper may still hold terminal resources Inspect ssh.exe and ssh-pageant.exe; stop only processes you no longer need
The error appears after opening and closing many sessions Shells or background processes may be retaining terminal resources Close unused sessions and inspect remaining processes
The error returns immediately after restarting Windows A startup helper, persistent runtime problem, or other allocation failure needs investigation Isolate automatic helper startup and update the affected installation
The message instead says “Resource temporarily unavailable,” especially with a DLL-rebasing note A broader process-creation or runtime-mapping problem Investigate that error separately rather than assuming SSH is responsible

What “No Available Terminals” Means

A terminal window needs more than a running shell. It also needs a pseudo-terminal, or PTY: the operating-system interface that lets an interactive program behave as though it is connected to a physical terminal.

For the BSD interfaces documented in Apple’s archived forkpty manual, openpty() obtains an available pseudo-terminal, while forkpty() combines terminal allocation, process creation, and terminal setup. In that documented implementation, ENOENT from openpty() means “There are no available ttys.”

The terminal-allocation message identifies the failed operation, not the process responsible for it.

A leftover SSH client or Pageant integration helper is worth checking, particularly when the failure follows SSH use. But other shells, background jobs, or launcher bugs can also retain resources.

In Apple’s documented BSD interfaces, an unsuccessful openpty(), login_tty(), or forkpty() call returns -1; errno carries the specific error. That return value alone does not distinguish terminal exhaustion from another failure, and forkpty() can fail because either terminal allocation or process creation failed.

These API details explain the diagnostic distinction. They do not establish a universal PTY limit for Cygwin, Git Bash, or every operating system.

How to Fix “No Available Terminals” on Windows

Work through these steps in order. Stop escalating once the terminal opens normally and survives the workflow that previously triggered the error.

Step 1: Preserve Active Work and Close Unused Sessions

  1. Save work in any terminal windows that still function. Check for running builds, file transfers, SSH tunnels, and remote commands before closing them.
  2. End unused interactive sessions normally rather than immediately terminating their processes.
  3. Close the failed terminal window and try opening a fresh terminal from your usual shortcut.

If that releases enough resources, the new shell should reach its normal prompt.

If the shell cannot open, use Windows-native tools for the remaining investigation. Task Manager and Command Prompt do not depend on the affected Cygwin or Git Bash shell.

Step 2: Identify Processes Left Behind

  1. Open Task Manager with Ctrl+Shift+Esc, then select Details.
  2. Right-click a column heading and choose Select columns. Make sure PID, User name, and Command line are visible.
  3. Look for ssh.exe and, if you use Pageant integration, ssh-pageant.exe. Also inspect unexpected bash.exe or mintty.exe processes remaining after their windows have closed.
  4. Check the executable location and command line before deciding which process belongs to the affected installation. Multiple Git, Cygwin, and SSH installations can coexist.

A process is not stale merely because its window is gone. An SSH tunnel, a background transfer, or an authentication helper may be running intentionally. Look for a process tied to a session you have already finished, rather than terminating everything with a familiar name.

Also distinguish an SSH client from an SSH server. A process named ssh.exe is not, by itself, an “SSH service” that should be stopped through Windows Services.

Step 3: Stop Only Confirmed Unneeded Processes

  1. In Task Manager, select a confirmed leftover process.
  2. Choose End task.
  3. Reopen the affected terminal and check whether the shell reaches its prompt.
  4. If it opens, repeat the activity that triggered the failure, close that session normally, and open the terminal again.

Targeting an individual process is preferable to killing every process with the same executable name.

For a command-line alternative, open Command Prompt from the Windows Start menu. If you have confirmed that no matching SSH client is needed, this command forcibly terminates the ssh.exe processes it has permission to stop:

taskkill /F /IM ssh.exe

Here, /IM selects an executable image name, and /F forces termination. This can disconnect active SSH sessions, interrupt transfers, and close tunnels, including ones unrelated to the broken terminal. It is not a targeted cleanup of only the faulty session.

After running it, reopen the terminal and test it. If the command reports that the process was not found, it has not identified or fixed the allocation problem; another process or cause may be involved.

For ssh-pageant.exe, use Task Manager to stop the specific unneeded helper rather than broadening the termination command blindly. Do not elevate privileges simply to kill processes whose purpose or owner you have not established.

Step 4: Restart Windows if Targeted Cleanup Does Not Work

  1. Save your work and end active remote operations where possible.
  2. Restart Windows through Start > Power > Restart.
  3. Open the affected terminal before launching your usual collection of development tools and terminal sessions.
  4. Test whether a new shell starts normally.

A restart clears the existing processes and their open handles, making it a useful recovery step when you cannot identify the resource owner. It does not, by itself, repair a launcher or helper that leaks resources.

If the terminal works after restarting but fails again after a particular workflow, record that trigger. If it fails immediately, investigate startup behavior and the installation rather than repeatedly terminating SSH processes.

Step 5: Isolate Startup Helpers and Update the Installation

If the problem persists or repeatedly returns:

  1. Back up your Bash startup files, such as .bashrc and .bash_profile.
  2. Temporarily disable only the commands you recognize as automatically launching SSH or Pageant integration helpers. Do not delete SSH keys, authentication configuration, or unrelated shell settings.
  3. Open the terminal from its normal shortcut and test it again.

If disabling a helper makes no difference, restore the original startup files. If it resolves the failure, leave that automatic launch disabled while correcting the helper’s startup and shutdown behavior. An authentication helper should not accumulate unnecessary instances every time a shell opens.

Next, update the installation that owns the failing terminal:

  • Git Bash: Close Git Bash and related running jobs, then run the current Git for Windows installer against the existing installation, retaining the installation choices you need.
  • Cygwin: Close Cygwin sessions and related jobs, then rerun Cygwin’s setup program for the existing installation and apply the available updates.

After the update finishes, launch the terminal, exercise the triggering workflow, close the session normally, and launch it again.

If it still fails, preserve the full error text, application version, executable location, and startup changes you tested. Those details provide a much better basis for a bug report than “Bash will not open.”

When “Resource Temporarily Unavailable” Needs Different Troubleshooting

“Could not fork child process: Resource temporarily unavailable” is not interchangeable with “There are no available terminals.”

The former can involve process-resource limits, runtime problems, or DLL/address-space mapping conflicts. A message that also mentions DLL rebasing deserves that separate investigation. Do not run rebasing tools solely because another error contains the word “fork.”

On Windows, recent exploit-protection changes are also relevant diagnostic information:

  1. Open Windows Security > App & Browser Control.
  2. Near the bottom, open Exploit Protection Settings.
  3. Select Program Settings.
  4. Inspect existing overrides for executables belonging to the affected installation, noting their full paths.

This is an inspection step, not an instruction to weaken protection. Record relevant overrides and leave settings unchanged unless current, tool-specific guidance establishes that a particular change is necessary.

Do not disable Mandatory ASLR system-wide or apply bulk mitigation-removal scripts as a general fix for “no available terminals.” On a managed computer, provide the exact error and applicable overrides to the administrator responsible for those policies.

How to Prevent PTY Leaks in a Custom Launcher

If you maintain a terminal application, wrapper, or process launcher, killing leftover processes treats the symptom. The lasting repair is correct ownership of terminal descriptors across allocation, fork, execution, and failure paths.

Record the Allocation Failure Precisely

Capture errno immediately after the failing call, before logging or cleanup operations can overwrite it.

Distinguish failure to allocate a PTY from failure to create the child. A generic “could not fork” message can conceal which operation actually failed, especially when the launcher uses a combined helper such as forkpty().

Retest the failing path after improving the logging. The diagnostic should identify the failing operation and its associated error, not just the helper’s return value.

Close Descriptors in Every Relevant Process

After a fork, parent and child descriptors can refer to the same underlying objects. Closing a terminal window therefore does not prove that all references to its terminal resources have disappeared.

According to Apple’s archived close documentation, a process’s descriptors are freed when it exits, but forked children inherit references to the same objects.

Audit the launcher so that:

  1. The parent closes PTY ends it does not need.
  2. The child closes descriptors it should not retain.
  3. Every startup-error path releases resources already allocated.
  4. Background children do not unintentionally keep terminal descriptors open.

Test both successful shell startup and failed startup. An error path that leaks descriptors can eventually prevent later, otherwise valid launches.

Set Close-on-Exec Where Inheritance Is Unwanted

For a custom launcher that forks before calling execve(), descriptors not intended for the executed program should be marked close-on-exec.

For its documented BSD interface, Apple gives this C call, not a shell command, to close descriptor d after a successful execve():

fcntl(d, F_SETFD, 1);

In new POSIX code, prefer the symbolic FD_CLOEXEC flag and preserve existing descriptor flags when updating them. Check the return value of the descriptor-control operation.

Do not indiscriminately apply this to the shell’s intended standard input, output, and error descriptors. Also retain explicit cleanup for failed execution: close-on-exec takes effect only when execution succeeds.

Finish by repeatedly opening and closing sessions, including failed launches, while checking that PTY-related descriptors do not accumulate.

How to Confirm the Fix and Prevent Recurrence

A terminal opening once establishes recovery, not necessarily a lasting fix. Confirm all of the following:

  • A fresh terminal reaches its normal shell prompt.
  • The SSH, Git, or helper workflow that previously triggered the failure now completes.
  • After ending that workflow and closing the shell normally, another terminal opens.
  • Task Manager does not show an unexplained accumulation of matching helper or shell processes.

For prevention, keep helper ownership explicit. A helper intended to be shared should not be started redundantly by every shell; a session-specific process should have a defined shutdown path. Long-lived agents can be intentional, so investigate unexplained growth rather than treating every surviving process as a leak.

If the error returns, capture the exact wording, affected executable paths and versions, triggering activity, and whether restarting Windows clears it. Use that evidence to isolate the responsible helper or file a focused issue with the affected project.

Frequently Asked Questions

What Is Returned by fork() in the Child Process?

A successful fork() returns 0 in the child process and the child’s process ID in the parent. The forkpty() interface documented by Apple uses the same success convention. If process creation fails, there is no child process to receive a return value.

Is “Bash: Fork: Retry: No Child Processes” the Same Error?

No. It concerns process creation or child-process handling and does not, by itself, identify a pseudo-terminal-allocation failure. Preserve the complete error and inspect process state, resource usage, and runtime diagnostics instead of assuming that terminating SSH clients will resolve it.

Why Does Git Bash Say “No Such File or Directory” When Starting a Child Process?

Git Bash’s “No such file or directory” error when starting a child process points toward a missing executable, an incorrect launcher command, or another required path that cannot be resolved, not necessarily exhausted terminals. Inspect the shortcut’s target and arguments, then verify that the configured shell exists in the installation the shortcut actually uses. Correct the target or repair the affected installation, then reopen Git Bash to verify startup.

Does “Can’t Determine Whether This Machine Supports Huge Files: No Child Processes” Mean Large Files Are Unsupported?

No; it means the capability check could not complete successfully. Restore normal process creation, then rerun the configuration or build check. A failed probe is not evidence that the filesystem or operating system lacks large-file support.