Why the process name in / proc / PID / status does not match the package name or ps command

The native application I wrote uses the variable name /proc/PID/status . However, it looks like the name variable in the status file is incomplete. For example, when testing, I opened the Android calculator and looked at the PID from PS and went to the corresponding /proc/PID folder. Then I go out to the status file to see

 Name: oid.calculator 

The PS command shows com.android.calculator . packages.xml shows com.android.calculator . I tested several other phones (Razr Maxx works 4.0.4, Google Nexus works with the same OS version) and noticed a similar behavior.

+6
source share
1 answer

It depends on the function of the Linux kernel: there are two different names for the process.

  • One of the names is the last component of the path to the executable, for example. native_executable if your application is located in /data/apps/com.example.hello/native_executable . This name appears in the Name /proc/PID/status field. The kernel truncates it to 15 characters, so in this case it contains native_executab .
  • Another name is passed by the program that calls the application as command line parameter # 0 ( argv[0] in C, args[0] in Java). This name appears at the beginning of /proc/PID/cmdline and ps displayed.
  • The path to the executable is also the target of the /proc/PID/exe symbolic link.

By convention, when a program launches another, it should use the name of the executable file as a command line parameter 0, but it can do it differently. In the Name /proc/PID/status field, the (truncated) name of the executable file by the kernel is always specified.

This is a common Linux feature - see also. Can I use standard tools to get the full process name when its name has embedded spaces? on Set Ubuntu .

The application itself can subsequently change both names (although there are length restrictions). Dalvik uses this feature to distinguish between applications: all applications come from the same native executable /sytem/bin/app_process ; instead of letting all of them be called app_process , the virtual machine changes both names as the name of the application package. The name in /proc/PID/status limited to 15 characters, so it is truncated. You can get a longer name from /proc/PID/cmdline (read to first zero byte).

+11
source

All Articles