# 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)

*** ** * ** ***


```
class ProcessCommands
```

<br />

*** ** * ** ***

Commands about processes.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/shell/command/ProcessCommands#getPid(kotlin.String)(processName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Gets the pid of a given process name. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/shell/command/ProcessCommands#isProcessAlive(kotlin.Int)(pid: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns whether the given process id is associated with a process that is alive. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/shell/command/ProcessCommands#killPid(kotlin.Int,kotlin.String)(pid: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, signal: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Kills a process with the given pid using the given signal. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/test/shell/command/ProcessPid>` | `https://developer.android.com/reference/kotlin/androidx/test/shell/command/ProcessCommands#processGrep(kotlin.String)(processName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Runs process grep (pgrep) with the given process name. |

## Public functions

### getPid

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

```
fun getPid(processName: String): Int
```

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/kotlin/androidx/test/shell/command/ProcessCommands#getPid(kotlin.String)`, or -1 if not found.

| Parameters |
|---|---|
| `processName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the name of the process to get the pid of. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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)

```
fun isProcessAlive(pid: Int): Boolean
```

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)

```
fun killPid(pid: Int, signal: String = "TERM"): Unit
```

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

| Parameters |
|---|---|
| `pid: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the pid of the process to kill. |
| `signal: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html = "TERM"` | 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)

```
fun processGrep(processName: String): List<ProcessPid>
```

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

| Parameters |
|---|---|
| `processName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the name of the process to grep for. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/test/shell/command/ProcessPid>` | a list of `https://developer.android.com/reference/kotlin/androidx/test/shell/command/ProcessPid` containing the pid and process name for each matching grep. |