[TinyTut] - Read out the PID(s) (ProcessID) of Activity

Tutorials with advanced 'difficulty' and more Lines of Code.

[TinyTut] - Read out the PID(s) (ProcessID) of Activity

Postby plusminus » Tue Dec 18, 2007 11:03 pm

[align=center][TinyTut] - Read out the PID(s) (ProcessID) of Activity/Processes[/align]

What you learn: You will learn how to read out the PID (ProcessID) of the current Activity using myPid(); and of all Processes using getPids(...,...);.

Difficulty: 0.5 of 5 :roll:

:idea: Questions/Problems: Simply post below...

What it will look like:
[align=center]Nothing to see here...[/align]

Description: This is a 1-liner, not much to explain :)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.os.Process;
  2.  
  3. // ...
  4.  
  5. int myProcessID = Process.myPid();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


There is a possibility to receive the PIDs of all Processes running on the Android-Device, called getPids(...):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. // Receive all ProcessIDs running on the device
  2.  
  3. int[] pids = Process.getPids("/proc", null);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Just to see it returns the correct results run a "ps" on the adb shell using the following CommandLine-Code:
Code: Select all
adb shell ps


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby aleho » Thu Mar 13, 2008 12:02 am

How is possibile to obtain information about processname, CPU utilization, ... only from PID?
aleho
Freshman
Freshman
 
Posts: 3
Joined: Thu Dec 27, 2007 10:50 pm

Postby sxjthefirst » Thu Mar 13, 2008 10:19 am

Just wanted to add this here. This displays the array of process ids in a list.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2.  
  3.  
  4.  
  5.        ...
  6.  
  7.         Process.getPids(arg0, arg1)
  8.  
  9.         int pids[]= Process.getPids("/proc", null);
  10.  
  11.         List<String> items = new ArrayList<String>() ;
  12.  
  13.         for (int i=0;i<pids.length;i++)
  14.  
  15.                 items.add(String.valueOf(pids[i]));
  16.  
  17.        
  18.  
  19.         ArrayAdapter<String> pid_list = new ArrayAdapter<String>(this, R.layout.task_row, items);
  20.  
  21.         this.setListAdapter(pid_list);
  22.  
  23.        ...
  24.  
  25.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
sxjthefirst
Developer
Developer
 
Posts: 36
Joined: Wed Mar 12, 2008 7:24 pm

Postby aleho » Thu Mar 13, 2008 11:11 am

That information I already found, and there is more information available in /proc/[pid] directory:
    cmdline - name of the process
    stat - process inforamtion including CPU utilization

but I have problem detect that the process is currently used by user. I need information which processes are in foreground and user is using them.
aleho
Freshman
Freshman
 
Posts: 3
Joined: Thu Dec 27, 2007 10:50 pm

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests