process id of a process

121 views
Skip to first unread message

Ubuntu guy

unread,
Jun 11, 2010, 2:39:58 PM6/11/10
to android-platform
Hi,

is there anyway to find out the process id by the process name? In
my case the process is executed by dalvik vm. I was hoping to find it
in android.os.process but no luck.

Dianne Hackborn

unread,
Jun 11, 2010, 2:58:24 PM6/11/10
to android-...@googlegroups.com
Process names are not unique.


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

San Mehat

unread,
Jun 11, 2010, 3:30:22 PM6/11/10
to android-...@googlegroups.com
On Fri, Jun 11, 2010 at 11:39 AM, Ubuntu guy <sam...@yahoo.co.in> wrote:


O_o

>
> --
> You received this message because you are subscribed to the Google Groups "android-platform" group.
> To post to this group, send email to android-...@googlegroups.com.
> To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
>
>

--
San Mehat  |  Staff Software Engineer  |  Android  |  Google Inc.
415.366.6172 (s...@google.com)

Ubuntu guy

unread,
Jun 11, 2010, 4:10:20 PM6/11/10
to android-platform
aren't they unique? I see them as com.android.phone all the time...

On Jun 11, 11:58 am, Dianne Hackborn <hack...@android.com> wrote:
> Process names are not unique.
>
>
>
>
>
> On Fri, Jun 11, 2010 at 11:39 AM, Ubuntu guy <sam_...@yahoo.co.in> wrote:
> > Hi,
>
> >  is there anyway to find out the process id by the process name? In
> > my case the process is executed by dalvik vm. I was hoping to find it
> > in android.os.process but no luck.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-platform" group.
> > To post to this group, send email to android-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-platfo...@googlegroups.com<android-platform%2Bunsubscrib­e...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.- Hide quoted text -
>
> - Show quoted text -

Dianne Hackborn

unread,
Jun 11, 2010, 4:53:25 PM6/11/10
to android-...@googlegroups.com
That is just a string.  There is no guarantee that multiple processes don't have the same name.

To unsubscribe from this group, send email to android-platfo...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Ubuntu guy

unread,
Jun 11, 2010, 5:00:25 PM6/11/10
to android-platform
Ok, in my case the name is going to be unique.
So could you share the java API to get the pid?

Dianne Hackborn

unread,
Jun 11, 2010, 5:55:09 PM6/11/10
to android-...@googlegroups.com
There isn't one.  Trying to find a process by name is just plain wrong.  It is not guaranteed to work, and is not secure, and any process can change its name so you can't know it is going to be unique.

This is just not the right way to do whatever you are trying to accomplish.

To unsubscribe from this group, send email to android-platfo...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer

San Mehat

unread,
Jun 11, 2010, 8:30:46 PM6/11/10
to android-...@googlegroups.com
On Fri, Jun 11, 2010 at 2:55 PM, Dianne Hackborn <hac...@android.com> wrote:
> There isn't one.  Trying to find a process by name is just plain wrong.  It
> is not guaranteed to work, and is not secure, and any process can change its
> name so you can't know it is going to be unique.
> This is just not the right way to do whatever you are trying to accomplish.
>

In the interests of protecting your (potential) users from security
issues, what are you trying
to do *exactly*?

-san

--

Ubuntu guy

unread,
Jun 14, 2010, 12:23:10 PM6/14/10
to android-platform
Well, this is not targetted for users. This was just for debugging
purpose where i'm
interested in knowing the details of other process from a different
process and for that
i need to know the other process's pid.

On Jun 11, 5:30 pm, San Mehat <s...@google.com> wrote:
> > answer them.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-platform" group.
> > To post to this group, send email to android-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-platfo...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.
>
> --
> San Mehat  |  Staff Software Engineer  |  Android  |  Google Inc.
> 415.366.6172 (s...@google.com)- Hide quoted text -

Johan Larsson

unread,
Jun 15, 2010, 10:13:02 AM6/15/10
to android-platform
From within an activity you can do:
int myPid = android.os.Process.myPid();
to get the pid for your app.

Or, you could do, with a bit of hacking:
//get all process-ids
String command = "ls /proc/";

//get the name of a id
String command = "cat /proc/<pid>/stat";
(will return a string, separated with spaces, where the second part is
the name of the process)

execute the commands with:

Process p = Runtime.getRuntime().exec(command);
BufferedReader in = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line = null;

while ((line = in.readLine()) != null)
{
//do something with the text in line..
}

br
/Johan
Reply all
Reply to author
Forward
0 new messages