Introduction to the Process Plugin

Understand what the Tauri Process Plugin is, why it is needed, and the real-world scenarios where controlling your app's own process from the frontend becomes essential.

The Tauri Process Plugin gives the web frontend of your application a safe, controlled way to tell the Rust backend "shut down" or "restart yourself." It wraps two fundamental actions every desktop application needs—exiting and restarting—into two simple cross‑platform commands: exit and relaunch.

Without this plugin, the JavaScript code running inside the WebView has no direct way to terminate the Rust process that hosts it or ask the whole app to start fresh. The plugin fills exactly that gap, and it does nothing else. It does not spawn new child processes, launch external applications, or open system shells. Those tasks live in the Shell Plugin.

What the Process Plugin Does

The plugin exposes two operations, available from both JavaScript and Rust:

  • Exit — Terminate the application process with a specific exit status code. A code of 0 signals success to the operating system; any non‑zero value conventionally means something went wrong.
  • Relaunch — Close the current application instance and start it again as a brand‑new process. This is the same application binary launching from scratch, not a live reload or a page refresh inside the same window.

Not a Process Spawner:

A common early mistake is reaching for the Process Plugin to open a terminal command or run an external binary. That belongs to the Shell Plugin. The Process Plugin only controls your own Tauri application process.

The plugin works across all Tauri desktop platforms—Windows, macOS, and Linux—and requires Rust version 1.77.2 or later.

Common Use Cases

These two operations solve a handful of practical problems that show up in nearly every desktop application. Here are the most frequent reasons developers reach for the Process Plugin.

Graceful Shutdown from the UI

A user clicks a "Quit" menu item or a close button you've custom‑built in React. Before the app actually disappears, you might want to save unsaved work, flush logs, or prompt for confirmation. The exit command gives you full control over when and how the process terminates.

// Inside a React component that handles quit
import { exit } from '@tauri-apps/plugin-process';
const handleQuit = async () => {
  // Save any pending state first
  await saveWorkspace();
  // Now exit cleanly
  await exit(0);
};

The exit status code matters. Automation scripts, CI pipelines, or parent processes that launched your Tauri app can check that code to understand whether the app finished correctly or encountered an error.

Restart After Changing Settings

Many apps have a "Restart to apply changes" workflow—changing a language, toggling hardware acceleration, or switching a theme that requires a fresh windowing setup. The relaunch command makes this a one‑line operation.

import { relaunch } from '@tauri-apps/plugin-process';
const handleApplySettings = async () => {
  await persistNewConfig();
  // Relaunch the whole app
  await relaunch();
};

When relaunch is called, the current process exits and a brand‑new instance of the same binary starts. Any state that was only in memory will be lost, so whatever needs to persist must be written to disk before calling relaunch.

Custom Error Codes for External Tooling

Tauri apps that integrate into larger workflows—build tools, automation scripts, monitoring dashboards—can use non‑zero exit codes to communicate failure modes to the outside world. A script that launches your app can inspect the exit code and decide what to do next.

import { exit } from '@tauri-apps/plugin-process';
try {
  await performCriticalOperation();
} catch (err) {
  console.error('Critical failure:', err);
  // Exit code 42 could signal a specific recoverable error
  await exit(42);
}

Programmatic Restart on Platform‑Specific Demands

Some operating system events, like a user changing the system appearance on macOS, might require a full application restart to pick up new window chrome or rendering paths. While the Tauri core handles many of these automatically, custom setups sometimes need a manual restart. The Process Plugin makes it available without platform‑specific code branches.

A First Look at the API

Once the plugin is installed and registered (both steps are covered on the Process Plugin page), the API is minimal. Here are the two functions you will use most often, shown side by side in JavaScript and Rust.

import { exit, relaunch } from '@tauri-apps/plugin-process';
// Terminate with status code 0 (success)
await exit(0);
// Restart the application
await relaunch();

Both sides call the same underlying mechanism. In the JavaScript case, an IPC message travels to the Rust backend, which executes the matching method on AppHandle. The Rust side can call these methods directly without any IPC overhead.

You're on the right track:

If after integrating the plugin you see your app close and reopen exactly as expected—with the OS treating it as a fresh launch—the plugin is working. The restart is a full process replacement; it is not the same as a window reload or a hot‑module replacement refresh.

How the Plugin Works Under the Hood

Even though the surface is tiny, understanding the mechanism helps avoid misusing the plugin.

When you call exit(0) from JavaScript, the plugin’s Rust command handler receives the status code and calls std::process::exit(code). This terminates the entire Rust process immediately. No Drop implementations run for the plugin or other Tauri state after that call—exit stops everything right there.

The relaunch function works differently. It uses Tauri’s AppHandle::restart, which spawns a new process from the same executable and then calls exit(0) on the current one. The operating system sees two separate processes: the old one dies, and a new one with a different process ID begins. The environment variables and command‑line arguments are preserved, so the new instance starts with the same configuration as the original.

Exit is Immediate:

Calling exit does not give you any asynchronous cleanup time. If you have pending file writes, open database connections, or unsaved state, handle that before the exit call. Once exit runs, the process is gone.

Beginners often assume relaunch behaves like a browser reload—that it just refreshes the WebView content. That is not what happens. A full restart destroys and recreates the Rust backend, which means managed state, the Tauri app handle, and any in‑memory data are lost. The frontend also reloads entirely. Always save what matters before calling either exit or relaunch.

Before You Dive into Setup

One of the most consequential mistakes when working with the Process Plugin is forgetting that its commands are protected by Tauri’s permission system. By default, no frontend code can call exit or relaunch. You must explicitly grant permission in your app’s capability configuration.

A minimal permission entry looks like this:

src-tauri/capabilities/default.json
{
  "permissions": [
    "process:default"
  ]
}

That single line enables both allow-exit and allow-restart. If you only need one of the two, you can grant them individually—the plugin’s permission table will be explained in plugin permissions.

Also, keep a clear mental separation: if your task involves running ping, ls, git, or any other external executable, you are looking for the Shell Plugin. The Process Plugin only ever talks about the Tauri application itself.

These permission and setup details receive full treatment in the upcoming pages. The goal here was to anchor you in what this plugin is and why it exists, so that the configuration steps feel purposeful rather than abstract.

Summary

The Process Plugin is the smallest Tauri plugin in terms of API surface—two functions—but it addresses a non‑negotiable requirement: letting the frontend control when the application ends or restarts. The API is identical in concept on both the JavaScript and Rust sides, and the plugin’s simplicity means there is not much to go wrong as long as you save your data first and grant the right permissions.

With this foundation, you are ready to exit, relaunch, and inspect the current process from your frontend.