# ProcessCommands

Artifact: [androidx.test.uiautomator:uiautomator-shell](https://developer.android.com/jetpack/androidx/releases/test-uiautomator) [View Source](https://cs.android.com/search?q=file:androidx/test/shell/command/ProcessCommands.kt+class:androidx.test.shell.command.ProcessCommands) Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

*** ** * ** ***


```
public final class ProcessCommands
```

<br />

*** ** * ** ***

Commands about processes.

## Summary

| ### Public methods |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/test/shell/command/ProcessCommands#getPid(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html processName)` Gets the pid of a given process name. |
| `final boolean` | `https://developer.android.com/reference/androidx/test/shell/command/ProcessCommands#isProcessAlive(kotlin.Int)(int pid)` Returns whether the given process id is associated with a process that is alive. |
| `final void` | `https://developer.android.com/reference/androidx/test/shell/command/ProcessCommands#killPid(kotlin.Int,kotlin.String)(int pid, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html signal)` Kills a process with the given pid using the given signal. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/ProcessPid>` | `https://developer.android.com/reference/androidx/test/shell/command/ProcessCommands#processGrep(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html processName)` Runs process grep (pgrep) with the given process name. |

## Public methods

### getPid

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final int getPid(@NonNull String processName)
```

Gets the pid of a given process name. Note that underlying this api utilizes pgrep and returns the pid associated to the first process with the name matching with the given `https://developer.android.com/reference/androidx/test/shell/command/ProcessCommands#getPid(kotlin.String)`, or -1 if not found.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html processName` | the name of the process to get the pid of. |

| Returns |
|---|---|
| `int` | the pid of the process if found or -1. |

### isProcessAlive

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final boolean isProcessAlive(int pid)
```

Returns whether the given process id is associated with a process that is alive.

### killPid

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final void killPid(int pid, @NonNull String signal)
```

Kills a process with the given pid using the given signal.

| Parameters |
|---|---|
| `int pid` | the pid of the process to kill. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html signal` | the name of the signal to send to the process. |

### processGrep

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public final @NonNull List<@NonNull ProcessPid> processGrep(@NonNull String processName)
```

Runs process grep (pgrep) with the given process name.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html processName` | the name of the process to grep for. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/shell/command/ProcessPid>` | a list of `https://developer.android.com/reference/androidx/test/shell/command/ProcessPid` containing the pid and process name for each matching grep. |