1e41f4b71Sopenharmony_ci# Startup in User Mode 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Startup of the Root Process in User Mode 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciThe 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. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci**Figure 1** Process tree 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci### Startup Process of the Root Process 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciUse the link script to place the following init startup code to the specified location in the system image. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci```c 19e41f4b71Sopenharmony_ci#define LITE_USER_SEC_ENTRY __attribute__((section(".user.entry"))) 20e41f4b71Sopenharmony_ciLITE_USER_SEC_ENTRY VOID OsUserInit(VOID *args) 21e41f4b71Sopenharmony_ci{ 22e41f4b71Sopenharmony_ci#ifdef LOSCFG_KERNEL_DYNLOAD 23e41f4b71Sopenharmony_ci sys_call3(__NR_execve, (UINTPTR)g_initPath, 0, 0); 24e41f4b71Sopenharmony_ci#endif 25e41f4b71Sopenharmony_ci while (true) { 26e41f4b71Sopenharmony_ci } 27e41f4b71Sopenharmony_ci} 28e41f4b71Sopenharmony_ci``` 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci> **NOTE** 31e41f4b71Sopenharmony_ci> 32e41f4b71Sopenharmony_ci> 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. 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ciUse **OsUserInitProcess** to start the **init** process. The procedure is as follows: 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci1. The kernel calls **OsLoadUserInit** to load the code for startup. 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci2. A process space is created to start the **/bin/init** process. 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci### Responsibilities of the Root Process 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci- The root process starts key system programs or services, such as shell. 44e41f4b71Sopenharmony_ci > **NOTE** 45e41f4b71Sopenharmony_ci > 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). 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci- The root process monitors the process for reclaiming the orphan process and clears the zombie processes in child processes. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci## Running Programs in User Mode 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ciA user-mode program can be started in either of the following ways: 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci- Using shell commands 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci ``` 57e41f4b71Sopenharmony_ci OHOS $ exec helloworld 58e41f4b71Sopenharmony_ci OHOS $ ./helloworld 59e41f4b71Sopenharmony_ci OHOS $ /bin/helloworld 60e41f4b71Sopenharmony_ci ``` 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci- Using POSIX APIs 63e41f4b71Sopenharmony_ci Use **Fork()** to create a process, and call **exec()** to execute a process. 64e41f4b71Sopenharmony_ci 65