Question: I am working on a script in which I need to supply the PID of my application. I am able to list all the processes with their PIDs by following command and could see the entry of my application.

> 
> adb shell ps
> 
> 
> 

This gives me a huge list of processes. And I need a single entry (which I can further supply to another command), so I want to filter this results with a package name. The grep command does not work on my windows machine. Also tried following command but it didn't help.

> 
> adb shell ps name:my\_app\_package
> 
> 
>

Answer: 
Instead of using `adb shell ps`, firstly enter `adb shell` and then use `ps`.

**Step by step:**

1. Enter `adb shell` command while a device (or emulator) is connected.  
(Command line prefix will be `shell@android:/ $` after executing this command.)
2. Enter `ps | grep <package_name_to_be_filtered>` (i.e. `ps | grep com.google`).

```
C:> adb shell
shell@android:/ $ ps | grep com.google
u0_a64  3353  2467  903744 52904 ffffffff 00000000 S com.google.process.location
u0_a64  3426  2467  893964 49452 ffffffff 00000000 S com.google.process.gapps

```
The processes shown by ps can be limited to those belonging to any given user by piping the output through grep, a filter that is used for searching text. For example, processes belonging to a user with a username adam can be displayed with the following:

```
ps -ef | grep adam

```

The -e option generates a list of information about every process currently running. The -f option generates a listing that contains fewer items of information for each process than the -l option.