• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Startup in User Mode
2
3
4## Startup of the Root Process in User Mode
5
6The root process is the first user-mode process in the system. The process ID is 1. The root process is the ancestor of all user-mode processes.
7
8**Figure 1** Process tree
9
10![](figures/process-tree.png "process-tree")
11
12
13### Startup Process of the Root Process
14
15Use the link script to place the following init startup code to the specified location in the system image.
16
17
18```c
19#define LITE_USER_SEC_ENTRY   __attribute__((section(".user.entry")))
20LITE_USER_SEC_ENTRY VOID OsUserInit(VOID *args)
21{
22#ifdef LOSCFG_KERNEL_DYNLOAD
23    sys_call3(__NR_execve, (UINTPTR)g_initPath, 0, 0);
24#endif
25    while (true) {
26    }
27}
28```
29
30> **NOTE**
31>
32> The preceeding code is in **kernel/liteos_a/kernel/user/src/los_user_init.c**. The value of **g_initPath** can be **/dev/shm/init** or **/bin/init**, depending on the startup settings.
33
34Use **OsUserInitProcess** to start the **init** process. The procedure is as follows:
35
361. The kernel calls **OsLoadUserInit** to load the code for startup.
37
382. A process space is created to start the **/bin/init** process.
39
40
41### Responsibilities of the Root Process
42
43- The root process starts key system programs or services, such as shell.
44  > **NOTE**
45  > In OpenHarmony, the **init** process reads **/etc/init.cfg** and runs commands or starts processes based on the configuration. For details, see [init Configuration File](../subsystems/subsys-boot-init-cfg.md).
46
47- The root process monitors the process for reclaiming the orphan process and clears the zombie processes in child processes.
48
49
50## Running Programs in User Mode
51
52A user-mode program can be started in either of the following ways:
53
54- Using shell commands
55
56  ```
57  OHOS $ exec helloworld
58  OHOS $ ./helloworld
59  OHOS $ /bin/helloworld
60  ```
61
62- Using POSIX APIs
63  Use **Fork()** to create a process, and call **exec()** to execute a process.
64
65