[android-kernel] creating new processes insternals

317 views
Skip to first unread message

Vesmar

unread,
May 6, 2010, 3:15:57 PM5/6/10
to Android Linux Kernel Development
Hi all,

Im studing how Android creates new processes and found two scenarios.

when I am running native programs on a terminal on Android (ps, ls,
mkdir, etc) all programs are created in the standard way, that is,
fork (clone) and execve system calls. The process name on task struct
is set by the putname() on the sys_execve syscall handler.

But when I run a Android application such the Calculator, for example,
i found 6 new tasks (processes or threads) forked by zygote. In fact,
zygote forks just one process and this new process spawns 4 new
processes and set their names using set_task_comm() and the last one
forks an aditional process. And at the last set_task_comm() is called
for the first forked process from zygote.

So there are two ways for set the task->comm field for a process: The
standard way (using execve and putname()) and a new way used by
Android using sys_prctl who calls set_task_comm().

Does anyone have more information on how processes are created on
Android and why a App needs all theis tasks forked by zygote? Why
execve is not used and what is used instead?

I m using Android for Mips using the Arriba QEMU emulator as my
experimentation platform.

Thanks,

--
unsubscribe: android-kerne...@googlegroups.com
website: http://groups.google.com/group/android-kernel

Hristo Bojinov

unread,
May 7, 2010, 12:11:13 AM5/7/10
to Android Linux Kernel Development
The Calculator is a Dalvik /"Java"/ app. All those get forked off of
zygote for performance reasons (zygote is an empty VM instance, ready
to spawn/fork off real apps; it has many libraries preloaded in its
address space, etc.).

http://developer.android.com/reference/dalvik/system/Zygote.html

Not sure why multiple threads though.

--Hristo

Dianne Hackborn

unread,
May 7, 2010, 5:02:09 PM5/7/10
to android...@googlegroups.com
2-3 threads are usually created for the binder IPC thread pool.
--
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.

Vesmar

unread,
May 8, 2010, 6:52:52 PM5/8/10
to Android Linux Kernel Development
Thank you guys!
Yes, I understand Android App are JAVA programs interpreted by Dalvik
VM. But I m trying to find a relation between the App point of view
(JAVA Apps, framework components, activities, services,..) vs. kernel
point of view (processes and threads). For this job I have modified
the Android emulator to provide me some additional information on a
non intruseve way (no instrumentantions techniques on the kernel were
used).

My objective is compare a linux + JAVA VM + User App with the Android
framework proposal.

To run a App. like a calculator, a standard linux the shell will will
fork and make a execv syscall to load the VM to interprete the app's
bytecode. Additional syscalls are App dependent. At the end, a
sys_exit will be called to terminate the process.

So on Android the "????" process will tell to the zygote process to
sys_clone (thread, fork or vfork?) and then the new zygote process
will load the "????" using the "????" syscall. Does this new zygote
will load a new dalvik image or just use the forkerd copy of the
parent? As far as I can see, no execve syscall is made, so I suposed a
forked copy is used. Is ii right?

Aditionally why binder threads are lauched? The only think I know
about binder is it a new IPC mechanisms ported from BeOS, so they are
kernel threads? does kernel thread uses the do_fork() kernel function
too? I didn't found a sys_exit syscall for these threads.

thanks in advance!



On 7 maio, 18:02, Dianne Hackborn <hack...@android.com> wrote:
> 2-3 threads are usually created for the binder IPC thread pool.
>
> > > unsubscribe: android-kerne...@googlegroups.com<android-kernel%2Bunsu...@googlegroups.com>
> > > website:http://groups.google.com/group/android-kernel
>
> > --
> > unsubscribe: android-kerne...@googlegroups.com<android-kernel%2Bunsu...@googlegroups.com>
> > website:http://groups.google.com/group/android-kernel
>
> --
> 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.
>
> --
> unsubscribe: android-kerne...@googlegroups.com
> website:http://groups.google.com/group/android-kernel

Dianne Hackborn

unread,
May 8, 2010, 10:15:49 PM5/8/10
to android...@googlegroups.com
On Sat, May 8, 2010 at 3:52 PM, Vesmar <ves...@gmail.com> wrote:
So on Android the "????" process will tell to the zygote process to
sys_clone (thread, fork or vfork?) and then the new zygote process
will load the "????" using the "????" syscall. Does this new zygote
will load a new dalvik image or just use the forkerd copy of the
parent? As far as I can see, no execve syscall is made, so I suposed a
forked copy is used. Is ii right?

The system process (running the activity manager) asks the zygote to fork a new process.  Once the new process is forked, it tells the activity manager it is ready, and the activity manager starts telling it what to do.  No exec is involved.
 
Aditionally why  binder threads are lauched? The only think I know
about binder is it a new IPC mechanisms ported from BeOS, so they are
kernel threads? does kernel thread uses the do_fork() kernel function
too? I didn't found a sys_exit syscall for these threads.

The binder threads, as I said, are for a thread pool to handling incoming IPCs.  They are threads, just like other threads, everything that is a thread is a standard Linux thread.  And these threads don't exit (nor do processes).

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

failuch

unread,
Jul 18, 2012, 12:02:31 PM7/18/12
to android...@googlegroups.com
Hello Dianne & all good people here

Concerning binder thread pool.

 I am new to the android and I am confused when  mentioned thread pool but I do not see in binder code
any thread creation ( aka kthread_create), the only thread that exists in binder driver is Garbage collector  .
Looking at he code I see that there is binder_thread object that counts ready_threads
My understanding that user space spawns threads but binder driver may limit access to service if  service application sets this limit calling ioctl( BINDER_SET_MAX_THREADS).

Can somebody clarify this issue ? (no threads created in kernel ?)



ThanX,
Failuch

On Thursday, May 6, 2010 10:15:57 PM UTC+3, Vesmar wrote:
Hi all,

I m studying how Android creates new processes and found two scenarios.
unsubscribe: android-kernel+unsubscribe@googlegroups.com
website: http://groups.google.com/group/android-kernel

Glenn Kasten

unread,
Jul 19, 2012, 12:26:23 PM7/19/12
to android...@googlegroups.com
in IPCThreadState::executeCommand() case BR_SPAWN_LOOPER:
the binder driver sends a command up to user level, suggesting that it create another thread
see frameworks/native(or base)/libs/binder/IPCThreadState.cpp
Reply all
Reply to author
Forward
0 new messages