<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Process/waitUntilExit()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTask(im)waitUntilExit"
  },
  "title" : "waitUntilExit()"
}
-->

# waitUntilExit()

Blocks the process until the receiver is finished.

```
func waitUntilExit()
```

## Discussion

This method first checks to see if the receiver is still running using [`isRunning`](/documentation/Foundation/Process/isRunning). Then it polls the current run loop using `NSDefaultRunLoopMode` until the task completes.

```objc
NSTask *task = // Create and initialize a task
[task launch];
[task waitUntilExit];
int status = [task terminationStatus];
 
if (status == 0) {
    NSLog(@"Task succeeded.");
} else {
    NSLog(@"Task failed.");
}
```

[`waitUntilExit()`](/documentation/Foundation/Process/waitUntilExit()) does not guarantee that the [`terminationHandler`](/documentation/Foundation/Process/terminationHandler) block has been fully executed before [`waitUntilExit()`](/documentation/Foundation/Process/waitUntilExit()) returns.

## See Also

[`-  launch`](/documentation/Foundation/Process/launch())

Launches the task represented by the receiver.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)