未验证 提交 b4a7a576 编写于 作者: O openharmony_ci 提交者: Gitee

!14548 [翻译完成】#I6863Y

Merge pull request !14548 from Annie_wang/PR12083A
......@@ -3,216 +3,98 @@
## Basic Concepts
In an OS that supports multiple tasks, modifying data in a memory area requires three steps: read data, modify data, and write data. However, data in a memory area may be simultaneously accessed by multiple tasks. If the data modification is interrupted by another task, the execution result of the operation is unpredictable.
In an OS that supports multiple tasks, modifying data in memory involves three steps: read data, modify data, and write data. However, the data may be simultaneously accessed by multiple tasks. If the data modification is interrupted by another task, an unexpected result will be caused.
Although you can enable or disable interrupts to ensure that the multi-task execution results meet expectations, the system performance is affected.
Although you can enable or disable interrupts to ensure expected results of multiple tasks, the system performance is affected.
The ARMv6 architecture has introduced the **LDREX** and **STREX** instructions to support more discreet non-blocking synchronization of the shared memory. The atomic operations implemented thereby can ensure that the "read-modify-write" operations on the same data will not be interrupted, that is, the operation atomicity is ensured.
The ARMv6 architecture has introduced the **LDREX** and **STREX** instructions to support more discreet non-blocking synchronization of the shared memory. The atomic operations implemented thereby can ensure that the "read-modify-write" operations on the same data will not be interrupted, that is, the operation atomicity is ensured.
## Working Principles
The OpenHarmony system has encapsulated the **LDREX** and **STREX** in the ARMv6 architecture to provide a set of atomic operation APIs.
- LDREX Rx, \[Ry\]
Reads the value in the memory and marks the exclusive access to the memory segment.
- Reads the 4-byte memory data pointed by the register **Ry** and saves the data to the **Rx** register.
- Adds an exclusive access flag to the memory area pointed by **Ry**.
- STREX Rf, Rx, \[Ry\]
Checks whether the memory has an exclusive access flag. If yes, the system updates the memory value and clears the flag. If no, the memory is not updated.
## Working Principles
- If there is an exclusive access flag, the system:
- Updates the **Rx** register value to the memory pointed to by the **Ry** register.
- Sets the **Rf** register to **0**.
OpenHarmony has encapsulated the **LDREX** and **STREX** in the ARMv6 architecture to provide a set of atomic operation APIs.
- If there is no exclusive access flag:
- The memory is not updated.
- The system sets the **Rf** register to **1**.
- LDREX Rx, [Ry]
Reads the value in the memory and marks the exclusive access to the memory segment.
- Reads the 4-byte memory data pointed by the register **Ry** and saves the data to the **Rx** register.
- Adds an exclusive access flag to the memory area pointed by **Ry**.
- STREX Rf, Rx, [Ry]
Checks whether the memory has an exclusive access flag. If yes, the system updates the memory value and clears the flag. If no, the memory is not updated.
- If there is an exclusive access flag, the system:
- Updates the **Rx** register value to the memory pointed to by the **Ry** register.
- Sets the **Rf** register to **0**.
- If there is no exclusive access flag:
- The memory is not updated.
- The system sets the **Rf** register to **1**.
- Flag register
- If the flag register is **0**, the system exits the loop and the atomic operation is complete.
- If the flag register is **1**, the system continues the loop and performs the atomic operation again.
- Flag register
- If the flag register is **0**, the system exits the loop and the atomic operation is complete.
- If the flag register is **1**, the system continues the loop and performs the atomic operation again.
## Development Guidelines
### Available APIs
The following table describes the APIs available for the OpenHarmony LiteOS-A kernel atomic operation module. For more details about the APIs, see the API reference.
**Table 1** Atomic operation APIs
<a name="table29217519171"></a>
<table><thead align="left"><tr id="row79375119172"><th class="cellrowborder" valign="top" width="21.21212121212121%" id="mcps1.2.4.1.1"><p id="p159375113174"><a name="p159375113174"></a><a name="p159375113174"></a>Function</p>
</th>
<th class="cellrowborder" valign="top" width="33.39333933393339%" id="mcps1.2.4.1.2"><p id="p199385118173"><a name="p199385118173"></a><a name="p199385118173"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="45.3945394539454%" id="mcps1.2.4.1.3"><p id="p18937511175"><a name="p18937511175"></a><a name="p18937511175"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row159315151712"><td class="cellrowborder" rowspan="2" valign="top" width="21.21212121212121%" headers="mcps1.2.4.1.1 "><p id="p593135115176"><a name="p593135115176"></a><a name="p593135115176"></a>Read</p>
</td>
<td class="cellrowborder" valign="top" width="33.39333933393339%" headers="mcps1.2.4.1.2 "><p id="p1193651181714"><a name="p1193651181714"></a><a name="p1193651181714"></a>LOS_AtomicRead</p>
</td>
<td class="cellrowborder" valign="top" width="45.3945394539454%" headers="mcps1.2.4.1.3 "><p id="p09316512178"><a name="p09316512178"></a><a name="p09316512178"></a>Reads 32-bit atomic data.</p>
</td>
</tr>
<tr id="row1493151161719"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p119395111718"><a name="p119395111718"></a><a name="p119395111718"></a>LOS_Atomic64Read</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p49311514178"><a name="p49311514178"></a><a name="p49311514178"></a>Reads 64-bit atomic data.</p>
</td>
</tr>
<tr id="row69365111712"><td class="cellrowborder" rowspan="2" valign="top" width="21.21212121212121%" headers="mcps1.2.4.1.1 "><p id="p199355111175"><a name="p199355111175"></a><a name="p199355111175"></a>Write</p>
</td>
<td class="cellrowborder" valign="top" width="33.39333933393339%" headers="mcps1.2.4.1.2 "><p id="p1693175191714"><a name="p1693175191714"></a><a name="p1693175191714"></a>LOS_AtomicSet</p>
</td>
<td class="cellrowborder" valign="top" width="45.3945394539454%" headers="mcps1.2.4.1.3 "><p id="p129320516173"><a name="p129320516173"></a><a name="p129320516173"></a>Sets 32-bit atomic data.</p>
</td>
</tr>
<tr id="row1593651111718"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p7944510176"><a name="p7944510176"></a><a name="p7944510176"></a>LOS_Atomic64Set</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p294115191713"><a name="p294115191713"></a><a name="p294115191713"></a>Sets 64-bit atomic data.</p>
</td>
</tr>
<tr id="row149495114177"><td class="cellrowborder" rowspan="6" valign="top" width="21.21212121212121%" headers="mcps1.2.4.1.1 "><p id="p1394165151718"><a name="p1394165151718"></a><a name="p1394165151718"></a>Add</p>
</td>
<td class="cellrowborder" valign="top" width="33.39333933393339%" headers="mcps1.2.4.1.2 "><p id="p494115112179"><a name="p494115112179"></a><a name="p494115112179"></a>LOS_AtomicAdd</p>
</td>
<td class="cellrowborder" valign="top" width="45.3945394539454%" headers="mcps1.2.4.1.3 "><p id="p1694155120174"><a name="p1694155120174"></a><a name="p1694155120174"></a>Adds 32-bit atomic data.</p>
</td>
</tr>
<tr id="row394651101719"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p179435113171"><a name="p179435113171"></a><a name="p179435113171"></a>LOS_Atomic64Add</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p594851181718"><a name="p594851181718"></a><a name="p594851181718"></a>Adds 64-bit atomic data.</p>
</td>
</tr>
<tr id="row294185110171"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1834102212615"><a name="p1834102212615"></a><a name="p1834102212615"></a>LOS_AtomicInc</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p129413519173"><a name="p129413519173"></a><a name="p129413519173"></a>Adds 1 to 32-bit atomic data.</p>
</td>
</tr>
<tr id="row1894175101713"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1981302213264"><a name="p1981302213264"></a><a name="p1981302213264"></a>LOS_Atomic64Inc</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p167671640113316"><a name="p167671640113316"></a><a name="p167671640113316"></a>Adds 1 to 64-bit atomic data.</p>
</td>
</tr>
<tr id="row12946512178"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1994051181716"><a name="p1994051181716"></a><a name="p1994051181716"></a>LOS_AtomicIncRet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p59414511172"><a name="p59414511172"></a><a name="p59414511172"></a>Adds 1 to 32-bit atomic data and returns the data.</p>
</td>
</tr>
<tr id="row1994551101712"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p129414519173"><a name="p129414519173"></a><a name="p129414519173"></a>LOS_Atomic64IncRet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1194951111713"><a name="p1194951111713"></a><a name="p1194951111713"></a>Adds 1 to 64-bit atomic data and returns the data.</p>
</td>
</tr>
<tr id="row1794451121719"><td class="cellrowborder" rowspan="6" valign="top" width="21.21212121212121%" headers="mcps1.2.4.1.1 "><p id="p179412517173"><a name="p179412517173"></a><a name="p179412517173"></a>Subtract</p>
</td>
<td class="cellrowborder" valign="top" width="33.39333933393339%" headers="mcps1.2.4.1.2 "><p id="p89495115176"><a name="p89495115176"></a><a name="p89495115176"></a>LOS_AtomicSub</p>
</td>
<td class="cellrowborder" valign="top" width="45.3945394539454%" headers="mcps1.2.4.1.3 "><p id="p18220416345"><a name="p18220416345"></a><a name="p18220416345"></a>Performs subtraction on 32-bit atomic data.</p>
</td>
</tr>
<tr id="row139485131718"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1894195116176"><a name="p1894195116176"></a><a name="p1894195116176"></a>LOS_Atomic64Sub</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p20822124173415"><a name="p20822124173415"></a><a name="p20822124173415"></a>Performs subtraction on 64-bit atomic data.</p>
</td>
</tr>
<tr id="row209505110175"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p7951051141713"><a name="p7951051141713"></a><a name="p7951051141713"></a>LOS_AtomicDec</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p382234117340"><a name="p382234117340"></a><a name="p382234117340"></a>Subtracts 1 from 32-bit atomic data.</p>
</td>
</tr>
<tr id="row995151171711"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p395151131715"><a name="p395151131715"></a><a name="p395151131715"></a>LOS_Atomic64Dec</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1982244117340"><a name="p1982244117340"></a><a name="p1982244117340"></a>Subtracts 1 from 64-bit atomic data.</p>
</td>
</tr>
<tr id="row895155117179"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p395155151719"><a name="p395155151719"></a><a name="p395155151719"></a>LOS_AtomicDecRet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p198222414349"><a name="p198222414349"></a><a name="p198222414349"></a>Subtracts 1 from 32-bit atomic data and returns the result.</p>
</td>
</tr>
<tr id="row59511518170"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1495125119175"><a name="p1495125119175"></a><a name="p1495125119175"></a>LOS_Atomic64DecRet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p198221841103419"><a name="p198221841103419"></a><a name="p198221841103419"></a>Subtracts 1 from 64-bit atomic data and returns the result.</p>
</td>
</tr>
<tr id="row159575131714"><td class="cellrowborder" rowspan="4" valign="top" width="21.21212121212121%" headers="mcps1.2.4.1.1 "><p id="p159585110177"><a name="p159585110177"></a><a name="p159585110177"></a>Swap</p>
</td>
<td class="cellrowborder" valign="top" width="33.39333933393339%" headers="mcps1.2.4.1.2 "><p id="p29515114174"><a name="p29515114174"></a><a name="p29515114174"></a>LOS_AtomicXchgByte</p>
</td>
<td class="cellrowborder" valign="top" width="45.3945394539454%" headers="mcps1.2.4.1.3 "><p id="p6956510177"><a name="p6956510177"></a><a name="p6956510177"></a>Swaps 8-bit memory data.</p>
</td>
</tr>
<tr id="row14951451111710"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p8952514173"><a name="p8952514173"></a><a name="p8952514173"></a>LOS_AtomicXchg16bits</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p12334173143919"><a name="p12334173143919"></a><a name="p12334173143919"></a>Swaps 16-bit memory data.</p>
</td>
</tr>
<tr id="row595251131716"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1495145117171"><a name="p1495145117171"></a><a name="p1495145117171"></a>LOS_AtomicXchg32bits</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p9951513173"><a name="p9951513173"></a><a name="p9951513173"></a>Swaps 32-bit memory data.</p>
</td>
</tr>
<tr id="row195165131718"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18951151141717"><a name="p18951151141717"></a><a name="p18951151141717"></a>LOS_AtomicXchg64bits</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p169685115172"><a name="p169685115172"></a><a name="p169685115172"></a>Swaps 64-bit memory data.</p>
</td>
</tr>
<tr id="row149616511175"><td class="cellrowborder" rowspan="4" valign="top" width="21.21212121212121%" headers="mcps1.2.4.1.1 "><p id="p49615120172"><a name="p49615120172"></a><a name="p49615120172"></a>Compare and swap</p>
</td>
<td class="cellrowborder" valign="top" width="33.39333933393339%" headers="mcps1.2.4.1.2 "><p id="p129605112171"><a name="p129605112171"></a><a name="p129605112171"></a>LOS_AtomicCmpXchgByte</p>
</td>
<td class="cellrowborder" valign="top" width="45.3945394539454%" headers="mcps1.2.4.1.3 "><p id="p6965510178"><a name="p6965510178"></a><a name="p6965510178"></a>Compares and swaps 8-bit memory data.</p>
</td>
</tr>
<tr id="row99605171713"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p109675131711"><a name="p109675131711"></a><a name="p109675131711"></a>LOS_AtomicCmpXchg16bits</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p17961951191719"><a name="p17961951191719"></a><a name="p17961951191719"></a>Compares and swaps 16-bit memory data.</p>
</td>
</tr>
<tr id="row169614513177"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p49645115172"><a name="p49645115172"></a><a name="p49645115172"></a>LOS_AtomicCmpXchg32bits</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p129611512175"><a name="p129611512175"></a><a name="p129611512175"></a>Compares and swaps 32-bit memory data.</p>
</td>
</tr>
<tr id="row696175110179"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p16961051161715"><a name="p16961051161715"></a><a name="p16961051161715"></a>LOS_AtomicCmpXchg64bits</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1296205118179"><a name="p1296205118179"></a><a name="p1296205118179"></a>Compares and swaps 64-bit memory data.</p>
</td>
</tr>
</tbody>
</table>
The following table describes the APIs available for the OpenHarmony LiteOS-A kernel atomic operation module.
**Table 1** APIs for atomic operations
| Category | API | Description |
| ------------ | ----------------------- | --------------------------- |
| Read | LOS_AtomicRead | Reads 32-bit atomic data. |
| Read | LOS_Atomic64Read | Reads 64-bit atomic data. |
| Write | LOS_AtomicSet | Sets 32-bit atomic data. |
| Write | LOS_Atomic64Set | Sets 64-bit atomic data. |
| Add | LOS_AtomicAdd | Adds 32-bit atomic data. |
| Add | LOS_Atomic64Add | Adds 64-bit atomic data. |
| Add | LOS_AtomicInc | Adds 1 to 32-bit atomic data. |
| Add | LOS_Atomic64Inc | Adds 1 to 64-bit atomic data. |
| Add | LOS_AtomicIncRet | Adds 1 to 32-bit atomic data and returns the data. |
| Add | LOS_Atomic64IncRet | Adds 1 to 64-bit atomic data and returns the data. |
| Subtract | LOS_AtomicSub | Performs subtraction on 32-bit atomic data. |
| Subtract | LOS_Atomic64Sub | Performs subtraction on 64-bit atomic data. |
| Subtract | LOS_AtomicDec | Subtracts 1 from 32-bit atomic data. |
| Subtract | LOS_Atomic64Dec | Subtracts 1 from 64-bit atomic data. |
| Subtract | LOS_AtomicDecRet | Subtracts 1 from 32-bit atomic data and returns the result. |
| Subtract | LOS_Atomic64DecRet | Subtracts 1 from 64-bit atomic data and returns the result. |
| Swap | LOS_AtomicXchgByte | Swaps 8-bit memory data. |
| Swap | LOS_AtomicXchg16bits | Swaps 16-bit memory data. |
| Swap | LOS_AtomicXchg32bits | Swaps 32-bit memory data. |
| Swap | LOS_AtomicXchg64bits | Swaps 64-bit memory data. |
| Compare and swap| LOS_AtomicCmpXchgByte | Compares and swaps 8-bit memory data. |
| Compare and swap| LOS_AtomicCmpXchg16bits | Compares and swaps 16-bit memory data.|
| Compare and swap| LOS_AtomicCmpXchg32bits | Compares and swaps 32-bit memory data.|
| Compare and swap| LOS_AtomicCmpXchg64bits | Compares and swaps 64-bit memory data.|
### How to Develop
When multiple tasks perform addition, subtraction, and swap operations on the same memory data, use atomic operations to ensure predictability of results.
>![](../public_sys-resources/icon-note.gif) **NOTE**<br/>
>Atomic operation APIs support only integer data.
> **NOTE**<br>
> Atomic operation APIs support only integers.
### Development Example<a name="section8538651511"></a>
### Development Example
Example Description
**Example Description**
Call the atomic operation APIs and observe the result.
1. Create two tasks.
- Task 1: Call **LOS\_AtomicInc** to add the global variables 100 times.
- Task 2: Call **LOS\_AtomicDec** to subtract the global variables 100 times.
1. Create two tasks.
- Task 1: Call **LOS_AtomicInc** to add a global variable 100 times.
- Task 2: Call **LOS_AtomicDec** to subtract a global variable 100 times.
2. After the subtasks are complete, print the values of the global variables in the main task.
2. After the subtasks are complete, print the values of the global variable in the main task.
**Sample Code**
The sample code is as follows:
```
#include "los_hwi.h"
#include "los_atomic.h"
......@@ -275,7 +157,7 @@ UINT32 Example_AtomicTaskEntry(VOID)
**Verification**
```
g_sum = 0
```
# Software Timer
## Basic Concepts<a name="section4118241563"></a>
## Basic Concepts
The software timer is a software-simulated timer based on system tick interrupts. When the preset tick counter value has elapsed, the user-defined callback will be invoked. The timing precision is related to the cycle of the system tick clock. Due to the limitation in hardware, the number of hardware timers cannot meet users' requirements. Therefore, the OpenHarmony LiteOS-A kernel provides the software timer function. The software timer allows more timing services to be created, increasing the number of timers.
The software timer is a software-simulated timer based on system tick interrupts. When the preset tick counter value has elapsed, the user-defined callback will be invoked. The timing precision is related to the cycle of the system tick clock.
Due to the limitation in hardware, the number of hardware timers cannot meet users' requirements. The OpenHarmony LiteOS-A kernel provides the software timer function.
The software timer allows more timing services to be created, increasing the number of timers.
The software timer supports the following functions:
- Disabling the software timer using a macro
- Creating a software timer
- Starting a software timer
- Stopping a software timer
- Deleting a software timer
- Obtaining the number of remaining ticks of a software timer
- Disabling the software timer using a macro
## Working Principles<a name="section31079397569"></a>
- Creating a software timer
The software timer is a system resource. When modules are initialized, a contiguous section of memory is allocated for software timers. The maximum number of timers supported by the system is configured by the **LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT** macro in **los\_config.h**. Software timers use a queue and a task resource of the system. The software timers are triggered based on the First In First Out \(FIFO\) rule. For the timers set at the same time, the timer with a shorter value is always closer to the queue head than the timer with a longer value, and is preferentially triggered. The software timer counts time in ticks. When a software timer is created and started, the OpenHarmony system determines the timer expiry time based on the current system time \(in ticks\) and the timing interval set by the user, and adds the timer control structure to the global timing list.
- Starting a software timer
- Stopping a software timer
- Deleting a software timer
- Obtaining the number of remaining ticks of a software timer
When a tick interrupt occurs, the tick interrupt handler scans the global timing list for expired timers. If such timers are found, the timers are recorded.
When the tick interrupt handling function is complete, the software timer task \(with the highest priority\) is woken up. In this task, the timeout callback function for the recorded timer is called.
## Working Principles
Timer States
The software timer is a system resource. When modules are initialized, a contiguous section of memory is allocated for software timers. The maximum number of timers supported by the system is configured by the **LOSCFG_BASE_CORE_SWTMR_LIMIT** macro in **los_config.h**.
- OS\_SWTMR\_STATUS\_UNUSED
Software timers use a queue and a task resource of the system. The software timers are triggered based on the First In First Out (FIFO) rule. For the timers set at the same time, the timer with a shorter value is always closer to the queue head than the timer with a longer value, and is preferentially triggered.
The timer is not in use. When the timer module is initialized, all timer resources in the system are set to this state.
The software timer counts time in ticks. When a software timer is created and started, the OpenHarmony system determines the timer expiry time based on the current system time (in ticks) and the timing interval set by the user, and adds the timer control structure to the global timing list.
- OS\_SWTMR\_STATUS\_CREATED
When a tick interrupt occurs, the tick interrupt handler scans the global timing list for expired timers. If such timers are found, the timers are recorded.
When the tick interrupt handler is complete, the software timer task (with the highest priority) will be woken up. In this task, the timeout callback for the recorded timer is called.
The timer is created but not started or the timer is stopped. When **LOS\_SwtmrCreate** is called for a timer that is not in use or **LOS\_SwtmrStop** is called for a newly started timer, the timer changes to this state.
A software timer can be in any of the following states:
- OS\_SWTMR\_STATUS\_TICKING
- OS_SWTMR_STATUS_UNUSED
The timer is not in use. When the timer module is initialized, all timer resources in the system are set to this state.
- OS_SWTMR_STATUS_CREATED
The timer is running \(counting\). When **LOS\_SwtmrStart** is called for a newly created timer, the timer enters this state.
The timer is created but not started or the timer is stopped. When **LOS_SwtmrCreate** is called for a timer that is not in use or **LOS_SwtmrStop** is called for a newly started timer, the timer changes to this state.
- OS_SWTMR_STATUS_TICKING
Timer Modes
The timer is running (counting). When **LOS_SwtmrStart** is called for a newly created timer, the timer enters this state.
The OpenHarmony provides three types of software timers:
OpenHarmony provides three types of software timers:
- One-shot timer: Once started, the timer is automatically deleted after triggering only one timer event.
- Periodic timer: This type of timer periodically triggers timer events until it is manually stopped.
- One-shot timer deleted by calling an API
## Development Guidelines<a name="section18576131520577"></a>
### Available APIs<a name="section3138019145719"></a>
The following table describes APIs available for the OpenHarmony LiteOS-A software timer module. For more details about the APIs, see the API reference.
**Table 1** Software timer APIs
<a name="table107038227425"></a>
<table><thead align="left"><tr id="row2704122217420"><th class="cellrowborder" valign="top" width="20.6020602060206%" id="mcps1.2.4.1.1"><p id="p57041622144212"><a name="p57041622144212"></a><a name="p57041622144212"></a>Function</p>
</th>
<th class="cellrowborder" valign="top" width="29.542954295429542%" id="mcps1.2.4.1.2"><p id="p19704142216424"><a name="p19704142216424"></a><a name="p19704142216424"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="49.85498549854985%" id="mcps1.2.4.1.3"><p id="p670412224217"><a name="p670412224217"></a><a name="p670412224217"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1470413222429"><td class="cellrowborder" rowspan="2" valign="top" width="20.6020602060206%" headers="mcps1.2.4.1.1 "><p id="p8284115918428"><a name="p8284115918428"></a><a name="p8284115918428"></a>Creating or deleting timers</p>
</td>
<td class="cellrowborder" valign="top" width="29.542954295429542%" headers="mcps1.2.4.1.2 "><p id="p117045225428"><a name="p117045225428"></a><a name="p117045225428"></a>LOS_SwtmrCreate</p>
</td>
<td class="cellrowborder" valign="top" width="49.85498549854985%" headers="mcps1.2.4.1.3 "><p id="p170422234213"><a name="p170422234213"></a><a name="p170422234213"></a>Creates a software timer.</p>
</td>
</tr>
<tr id="row11704102217425"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1970492213426"><a name="p1970492213426"></a><a name="p1970492213426"></a>LOS_SwtmrDelete</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p870442211421"><a name="p870442211421"></a><a name="p870442211421"></a>Deletes a software timer.</p>
</td>
</tr>
<tr id="row57041422184215"><td class="cellrowborder" rowspan="2" valign="top" width="20.6020602060206%" headers="mcps1.2.4.1.1 "><p id="p1476172124318"><a name="p1476172124318"></a><a name="p1476172124318"></a>Starting or stopping timers</p>
</td>
<td class="cellrowborder" valign="top" width="29.542954295429542%" headers="mcps1.2.4.1.2 "><p id="p167040225423"><a name="p167040225423"></a><a name="p167040225423"></a>LOS_SwtmrStart</p>
</td>
<td class="cellrowborder" valign="top" width="49.85498549854985%" headers="mcps1.2.4.1.3 "><p id="p1570412229421"><a name="p1570412229421"></a><a name="p1570412229421"></a>Starts a software timer.</p>
</td>
</tr>
<tr id="row15704172224219"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1170422214216"><a name="p1170422214216"></a><a name="p1170422214216"></a>LOS_SwtmrStop</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p17705122211426"><a name="p17705122211426"></a><a name="p17705122211426"></a>Stops a software timer.</p>
</td>
</tr>
<tr id="row12705222154214"><td class="cellrowborder" valign="top" width="20.6020602060206%" headers="mcps1.2.4.1.1 "><p id="p0705622134214"><a name="p0705622134214"></a><a name="p0705622134214"></a>Obtaining remaining ticks of a software timer</p>
</td>
<td class="cellrowborder" valign="top" width="29.542954295429542%" headers="mcps1.2.4.1.2 "><p id="p177052220424"><a name="p177052220424"></a><a name="p177052220424"></a>LOS_SwtmrTimeGet</p>
</td>
<td class="cellrowborder" valign="top" width="49.85498549854985%" headers="mcps1.2.4.1.3 "><p id="p3705122264210"><a name="p3705122264210"></a><a name="p3705122264210"></a>Obtains the number of remaining ticks of a software timer.</p>
</td>
</tr>
</tbody>
</table>
### How to Develop<a name="section1344817403575"></a>
## Development Guidelines
### Available APIs
The following table describes the APIs of the software timer module of the OpenHarmony LiteOS-A kernel.
**Table 1** APIs for software timers
| Category | Description |
| ---------------------- | ------------------------------------------------------------ |
| Creating or deleting a timer | **LOS_SwtmrCreate**: creates a software timer.<br>**LOS_SwtmrDelete**: deletes a software timer.|
| Starting or stopping a timer | **LOS_SwtmrStart**: starts a software timer.<br>**LOS_SwtmrStop**: stops a software timer.|
| Obtaining remaining ticks of a software timer| **LOS_SwtmrTimeGet**: obtains the remaining ticks of a software timer. |
### How to Develop
The typical development process of software timers is as follows:
1. Configure the software timer.
- Check that **LOSCFG\_BASE\_CORE\_SWTMR** and **LOSCFG\_BASE\_IPC\_QUEUE** are enabled.
- Configure **LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT** \(maximum number of software timers supported by the system\).
- Configure **OS\_SWTMR\_HANDLE\_QUEUE\_SIZE** \(maximum length of the software timer queue\).
1. Configure the software timer.
- Check that **LOSCFG_BASE_CORE_SWTMR** and **LOSCFG_BASE_IPC_QUEUE** are enabled.
- Configure **LOSCFG_BASE_CORE_SWTMR_LIMIT** (maximum number of software timers supported by the system).
- Configure **OS_SWTMR_HANDLE_QUEUE_SIZE** (maximum length of the software timer queue).
2. Call **LOS_SwtmrCreate** to create a software timer.
- Create a software timer with the specified timing duration, timeout handling function, and triggering mode.
- Return the function execution result (success or failure).
3. Call **LOS_SwtmrStart** to start the software timer.
2. Call **LOS\_SwtmrCreate** to create a software timer.
- Create a software timer with the specified timing duration, timeout handling function, and triggering mode.
- Return the function execution result \(success or failure\).
4. Call **LOS_SwtmrTimeGet** to obtain the remaining number of ticks of the software timer.
3. Call **LOS\_SwtmrStart** to start the software timer.
4. Call **LOS\_SwtmrTimeGet** to obtain the remaining number of ticks of the software timer.
5. Call **LOS\_SwtmrStop** to stop the software timer.
6. Call **LOS\_SwtmrDelete** to delete the software timer.
5. Call **LOS_SwtmrStop** to stop the software timer.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>- Avoid too many operations in the callback function of the software timer. Do not use APIs or perform operations that may cause task suspension or blocking.
>- The software timers use a queue and a task resource of the system. The priority of the software timer tasks is set to **0** and cannot be changed.
>- The number of software timer resources that can be configured in the system is the total number of software timer resources available to the entire system, not the number of software timer resources available to users. For example, if the system software timer occupies one more resource, the number of software timer resources available to users decreases by one.
>- If a one-shot software timer is created, the system automatically deletes the timer and reclaims resources after the timer times out and the callback function is executed.
>- For a one-shot software timer that will not be automatically deleted after expiration, you need to call **LOS\_SwtmrDelete** to delete it and reclaim the timer resource to prevent resource leakage.
6. Call **LOS_SwtmrDelete** to delete the software timer.
### Development Example<a name="section114416313585"></a>
> **NOTE**<br>
>
> - Avoid too many operations in the callback of the software timer. Do not use APIs or perform operations that may cause task suspension or blocking.
>
> - The software timers use a queue and a task resource of the system. The priority of the software timer tasks is set to **0** and cannot be changed.
>
> - The number of software timer resources that can be configured in the system is the total number of software timer resources available to the entire system, not the number of software timer resources available to users. For example, if the system software timer occupies one more resource, the number of software timer resources available to users decreases by one.
>
> - If a one-shot software timer is created, the system automatically deletes the timer and reclaims resources after the timer times out and the callback is invoked.
>
> - For a one-shot software timer that will not be automatically deleted after expiration, you need to call **LOS_SwtmrDelete** to delete it and reclaim the timer resource to prevent resource leakage.
Prerequisites:
- In **los\_config.h**, **LOSCFG\_BASE\_CORE\_SWTMR** is enabled.
- The maximum number of software timers supported by the system \(**LOSCFG\_BASE\_CORE\_SWTMR\_LIMIT**\) is configured.
- The maximum length of the software timer queue \(**OS\_SWTMR\_HANDLE\_QUEUE\_SIZE**\) is configured.
### Development Example
**Prerequisites**
- In **los_config.h**, **LOSCFG_BASE_CORE_SWTMR** is enabled.
- The maximum number of software timers supported by the system (**LOSCFG_BASE_CORE_SWTMR_LIMIT**) is configured.
- The maximum length of the software timer queue (**OS_SWTMR_HANDLE_QUEUE_SIZE**) is configured.
**Sample Code**
......@@ -164,14 +150,14 @@ void Timer_example(void)
UINT16 id2; // timer id
UINT32 uwTick;
/* Create a one-shot software timer, with the number of ticks set to 1000. When the number of ticks reaches 1000, callback function 1 is executed. */
/* Create a one-shot software timer, with the number of ticks set to 1000. Callback 1 will be invoked when the number of ticks reaches 1000. */
LOS_SwtmrCreate (1000, LOS_SWTMR_MODE_ONCE, Timer1_Callback, &id1, 1);
/* Create a periodic software timer and execute callback function 2 every 100 ticks. */
/* Create a periodic software timer and invoke callback 2 every 100 ticks. */
LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1);
PRINTK("create Timer1 success\n");
LOS_SwtmrStart (id1); // Start the one-shot software timer.
LOS_SwtmrStart(id1); // Start the one-shot software timer.
dprintf("start Timer1 success\n");
LOS_TaskDelay(200); // Delay 200 ticks.
LOS_SwtmrTimeGet(id1, &uwTick); // Obtain the number of remaining ticks of the one-short software timer.
......@@ -196,6 +182,7 @@ void Timer_example(void)
**Output**
```
create Timer1 success
start Timer1 success
......@@ -226,4 +213,3 @@ tick_last1=2101
g_timercount2 =10
tick_last1=2201
```
......@@ -3,85 +3,64 @@
## Basic Concepts
Time management provides all time-related services for applications based on the system clock. The system clock is generated by the interrupts triggered by the output pulse of a timer or counter. The system clock is generally defined as an integer or a long integer. The period of an output pulse is a "clock tick". The system clock is also called time scale or tick. The duration of a tick can be configured statically. People use second or millisecond as the time unit, while the operating system uses tick. When operations such as suspending a task or delaying a task are performed, the time management module converts time between ticks and seconds or milliseconds.
Time management is performed based on the system clock. It provides time-related services for applications. The system clock is generated by the interrupts triggered by the output pulse of a timer or counter. The system clock is generally defined as an integer or a long integer. The period of an output pulse is a "clock tick".
The system clock is also called time scale or tick. The duration of a tick can be configured statically. People use second or millisecond as the time unit, while the operating system uses tick. When operations such as suspending a task or delaying a task are performed, the time management module converts time between ticks and seconds or milliseconds.
The mapping between ticks and seconds can be configured.
- **Cycle**
- Cycle
Cycle is the minimum time unit in the system. The cycle duration is determined by the system clock frequency, that is, the number of cycles per second.
- Tick
Cycle is the minimum time unit in the system. The cycle duration is determined by the system clock frequency, that is, the number of cycles per second.
Tick is the basic time unit of the operating system and is determined by the number of ticks per second configured by the user.
The OpenHarmony time management module provides time conversion, statistics, and delay functions.
- **Tick**
Tick is the basic time unit of the operating system and is determined by the number of ticks per second configured by the user.
## Development Guidelines
Before you start, learn about the system time and the APIs for time management.
The OpenHarmony time management module provides time conversion, statistics, and delay functions to meet users' time requirements.
## Development Guidelines
### Available APIs
The time management module provides APIs to implement conversion between the system running time, ticks, and seconds/milliseconds.
The following table describes APIs for OpenHarmony LiteOS-A time management. For more details about the APIs, see the API reference.
### Available APIs
**Table 1** APIs for time management
| Category| API Description |
| -------- | ------------------------------------------------------------ |
| Time conversion| **LOS_MS2Tick**: converts milliseconds to ticks.<br>**LOS_Tick2MS**: converts ticks to milliseconds. |
| Time statistics| **LOS_TickCountGet**: obtains the number of current ticks.<br>**LOS_CyclePerTickGet**: obtains the number of cycles of each tick.|
The following table describes APIs available for the OpenHarmony LiteOS-A time management. For more details about the APIs, see the API reference.
**Table 1** APIs of the time management module
<a name="table1316220185211"></a>
<table><thead align="left"><tr id="row191622182021"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p13162121815218"><a name="p13162121815218"></a><a name="p13162121815218"></a>Function</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p12162618623"><a name="p12162618623"></a><a name="p12162618623"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p16162118427"><a name="p16162118427"></a><a name="p16162118427"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row04981218910"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p6462616696"><a name="p6462616696"></a><a name="p6462616696"></a>Time conversion</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p164931214913"><a name="p164931214913"></a><a name="p164931214913"></a>LOS_MS2Tick</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p8504121996"><a name="p8504121996"></a><a name="p8504121996"></a>Converts milliseconds into ticks.</p>
</td>
</tr>
<tr id="row7162101814216"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p816311185217"><a name="p816311185217"></a><a name="p816311185217"></a>LOS_Tick2MS</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p161632181721"><a name="p161632181721"></a><a name="p161632181721"></a>Converts ticks into milliseconds.</p>
</td>
</tr>
<tr id="row1516317181227"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p1077619231696"><a name="p1077619231696"></a><a name="p1077619231696"></a>Time statistics</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p181638181921"><a name="p181638181921"></a><a name="p181638181921"></a>LOS_TickCountGet</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p615864811116"><a name="p615864811116"></a><a name="p615864811116"></a>Obtains the current number of ticks.</p>
</td>
</tr>
<tr id="row101631818620"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p71633181125"><a name="p71633181125"></a><a name="p71633181125"></a>LOS_CyclePerTickGet</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p151631718124"><a name="p151631718124"></a><a name="p151631718124"></a>Obtains the number of cycles per tick.</p>
</td>
</tr>
</tbody>
</table>
### How to Develop
1. Call APIs to convert time.
2. Call APIs to perform time statistics.
1. Call APIs to convert time.
2. Call APIs to perform time statistics.
> **NOTE**
>
> - The system tick count can be obtained only after the system clock is enabled.
>
> - The time management module depends on **OS_SYS_CLOCK** and **LOSCFG_BASE_CORE_TICK_PER_SECOND** in **los_config.h**.
>
> - The number of system ticks is not counted when the interrupt feature is disabled. Therefore, the number of ticks cannot be used as the accurate time.
>![](public_sys-resources/icon-note.gif) **NOTE**<br/>
>- The system tick count can be obtained only after the system clock is enabled.
>- The time management module depends on **OS\_SYS\_CLOCK** and **LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND** in **los\_config.h**.
>- The number of system ticks is not counted when the interrupt feature is disabled. Therefore, the number of ticks cannot be used as the accurate time.
### Development Example
**Prerequisites**<br>
**Prerequisites**
The following parameters are configured:
- **LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND**: number of ticks per second in the system. The value range is (0, 1000].
- **OS\_SYS\_CLOCK**: system clock, in Hz.
- **LOSCFG_BASE_CORE_TICK_PER_SECOND**: number of ticks/second. The value range is (0, 1000).
- **OS_SYS_CLOCK**: system clock, in Hz.
**Sample Code**
......@@ -92,15 +71,16 @@ VOID Example_TransformTime(VOID)
{
UINT32 uwMs;
UINT32 uwTick;
uwTick = LOS_MS2Tick(10000);// Convert 10000 ms into ticks.
uwTick = LOS_MS2Tick(10000); // Convert 10000 ms to ticks.
PRINTK("uwTick = %d \n",uwTick);
uwMs= LOS_Tick2MS(100); // Convert 100 ticks into ms.
uwMs= LOS_Tick2MS(100); // Convert 100 ticks to ms.
PRINTK("uwMs = %d \n",uwMs);
}
```
Time statistics and delay:
```
VOID Example_GetTime(VOID)
{
......@@ -133,6 +113,7 @@ The result is as follows:
Time conversion:
```
uwTick = 10000
uwMs = 100
......@@ -140,9 +121,9 @@ uwMs = 100
Time statistics and delay:
```
LOS_CyclePerTickGet = 49500
LOS_TickCountGet = 5042
LOS_TickCountGet after delay = 5242
LOS_TickCountGet = 347931
LOS_TickCountGet after delay = 348134
```
......@@ -9,29 +9,25 @@ A mutex has three attributes: protocol attribute, priority upper limit attribute
- LOS_MUX_PRIO_NONE
Do not inherit or protect the priority of the task requesting the mutex.
Do not inherit or protect the priority of the task requesting the mutex.
- LOS_MUX_PRIO_INHERIT
Inherits the priority of the task that requests the mutex. This is the default protocol attribute. When the mutex protocol attribute is set to this value: If a task with a higher priority is blocked because the mutex is already held by a task, the priority of the task holding the mutex will be backed up to the priority bitmap of the task control block, and then set to be the same as that of the task of a higher priority. When the task holding the mutex releases the mutex, its task priority is restored to its original value.
Inherits the priority of the task that requests the mutex. This is the default protocol attribute. When the mutex protocol attribute is set to this value: If a task with a higher priority is blocked because the mutex is already held by a task, the priority of the task holding the mutex will be backed up to the priority bitmap of the task control block, and then set to be the same as that of the task of a higher priority. When the task holding the mutex releases the mutex, its task priority is restored to its original value.
- LOS_MUX_PRIO_PROTECT
Protects the priority of the task that requests the mutex. When the mutex protocol attribute is set to this value: If the priority of the task that requests the mutex is lower than the upper limit of the mutex priority, the task priority will be backed up to the priority bitmap of the task control block, and then set to the upper limit value of the mutex priority. When the mutex is released, the task priority is restored to its original value.
The type attribute of a mutex specifies whether to check for deadlocks and whether to support recursive holding of the mutex. The type attribute can be any of the following:
The type attribute of a mutex specifies whether to check for deadlocks and whether to support recursive holding of the mutex. The type attribute can be any of the following:
- LOS_MUX_NORMAL
Common mutex, which does not check for deadlocks. If a task repeatedly attempts to hold a mutex, the thread will be deadlocked. If the mutex type attribute is set to this value, a task cannot release a mutex held by another task or repeatedly release a mutex. Otherwise, unexpected results will be caused.
Common mutex, which does not check for deadlocks. If a task repeatedly attempts to hold a mutex, the thread will be deadlocked. If the mutex type attribute is set to this value, a task cannot release a mutex held by another task or repeatedly release a mutex. Otherwise, unexpected results will be caused.
- LOS_MUX_RECURSIVE
Recursive mutex, which is the default attribute. If the type attribute of a mutex is set to this value, a task can hold the mutex for multiple times. Another task can hold this mutex only when the number of lock holding times is the same as the number of lock release times. However, any attempt to hold a mutex held by another task or attempt to release a mutex that has been released will return an error code.
Recursive mutex, which is the default attribute. If the type attribute of a mutex is set to this value, a task can hold the mutex for multiple times. Another task can hold this mutex only when the number of lock holding times is the same as the number of lock release times. However, any attempt to hold a mutex held by another task or attempt to release a mutex that has been released will return an error code.
- LOS_MUX_ERRORCHECK
......@@ -44,7 +40,7 @@ In a multi-task environment, multiple tasks may access the same shared resources
When non-shared resources are accessed by a task, the mutex is locked. Other tasks will be blocked until the mutex is released by the task. The mutex allows only one task to access the shared resources at a time, ensuring integrity of operations on the shared resources.
**Figure 1** Mutex working mechanism for the small system
**Figure 1** Mutex working mechanism for the small system
![](figures/mutex-working-mechanism-for-small-systems.png "mutex-working-mechanism-for-small-systems")
......
# Futex
## Basic Concepts<a name="section643519912920"></a>
## Basic Concepts
Fast userspace mutex \(futex\) is a system call capability provided by the kernel. It is a basic component that combines with user-mode lock logic to form a user-mode lock. It is a lock working in both user mode and kernel mode, for example, userspace mutex, barrier and cond synchronization lock, and RW lock. The user-mode part implements lock logic, and the kernel-mode part schedules locks.
Fast userspace mutex (futex) is a system call capability provided by the kernel. It is a basic component that combines with user-mode lock logic to form a user-mode lock. It is a lock working in both user mode and kernel mode, for example, userspace mutex, barrier and cond synchronization lock, and RW lock. The user-mode part implements lock logic, and the kernel-mode part schedules locks.
When a user-mode thread requests a lock, the lock status is first checked in user space. If no lock contention occurs, the user-mode thread acquires the lock directly. If lock contention occurs, the futex system call is invoked to request the kernel to suspend the thread and maintain the blocking queue.
When a user-mode thread releases a lock, the lock status is first checked in user space. If no other thread is blocked by the lock, the lock is directly released in user space. If there are threads blocked by the lock, the futex system call is invoked to request the kernel to wake up the threads in the blocking queue.
## Working Principles<a name="section16834132502910"></a>
## Working Principles
When thread scheduling is required to resolve lock contention or lock release in user space, the futex system call is invoked to pass the user-mode lock address to the kernel. The user-mode locks are distinguished by lock address in the futex of the kernel. The available virtual address space in user space is 1 GiB. To facilitate search and management of lock addresses, the kernel futex uses hash buckets to store the user-mode locks.
There are 80 hash buckets. Buckets 0 to 63 are used to store private locks \(hashed based on virtual addresses\), and buckets 64 to 79 are used to store shared locks \(hashed based on physical addresses\). The private/shared attributes are determined by initialization of user-mode locks and the input parameters in the futex system call.
There are 80 hash buckets used to store shared locks (hashed based on physical addresses). The private/shared attributes are determined by initialization of user-mode locks and the input parameters in the futex system call.
## Futex Design
**Figure 1** Futex design
**Figure 1** Futex design<a name="fig651353710598"></a>
![](figures/futex-design.jpg "futex-design")
As shown in the above figure, each futex hash bucket stores the futex nodes with the same hash value linked in a futex\_list. Each futex node corresponds to a suspended task. The key value of a node uniquely identifies a user-mode lock. The nodes with the same key value added to a queue\_list indicate a queue of tasks blocked by the same lock.
The following table describes the APIs available for the futex module.
**Table 1** Futex module APIs
<a name="table1316220185211"></a>
<table><thead align="left"><tr id="row191622182021"><th class="cellrowborder" valign="top" width="27.09270927092709%" id="mcps1.2.4.1.1"><p id="p13162121815218"><a name="p13162121815218"></a><a name="p13162121815218"></a>Function</p>
</th>
<th class="cellrowborder" valign="top" width="26.52265226522652%" id="mcps1.2.4.1.2"><p id="p12162618623"><a name="p12162618623"></a><a name="p12162618623"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="46.384638463846386%" id="mcps1.2.4.1.3"><p id="p16162118427"><a name="p16162118427"></a><a name="p16162118427"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row04981218910"><td class="cellrowborder" valign="top" width="27.09270927092709%" headers="mcps1.2.4.1.1 "><p id="p6462616696"><a name="p6462616696"></a><a name="p6462616696"></a>Putting a thread to wait</p>
</td>
<td class="cellrowborder" valign="top" width="26.52265226522652%" headers="mcps1.2.4.1.2 "><p id="p164931214913"><a name="p164931214913"></a><a name="p164931214913"></a>OsFutexWait</p>
</td>
<td class="cellrowborder" valign="top" width="46.384638463846386%" headers="mcps1.2.4.1.3 "><p id="p8504121996"><a name="p8504121996"></a><a name="p8504121996"></a>Inserts a node representing a blocked thread into the futex list.</p>
</td>
</tr>
<tr id="row7162101814216"><td class="cellrowborder" valign="top" width="27.09270927092709%" headers="mcps1.2.4.1.1 "><p id="p37331032985"><a name="p37331032985"></a><a name="p37331032985"></a>Waking up a thread</p>
</td>
<td class="cellrowborder" valign="top" width="26.52265226522652%" headers="mcps1.2.4.1.2 "><p id="p816311185217"><a name="p816311185217"></a><a name="p816311185217"></a>OsFutexWake</p>
</td>
<td class="cellrowborder" valign="top" width="46.384638463846386%" headers="mcps1.2.4.1.3 "><p id="p161632181721"><a name="p161632181721"></a><a name="p161632181721"></a>Wakes up a thread that is blocked by a specified lock.</p>
</td>
</tr>
<tr id="row101631818620"><td class="cellrowborder" valign="top" width="27.09270927092709%" headers="mcps1.2.4.1.1 "><p id="p146111936887"><a name="p146111936887"></a><a name="p146111936887"></a>Modifying the lock address</p>
</td>
<td class="cellrowborder" valign="top" width="26.52265226522652%" headers="mcps1.2.4.1.2 "><p id="p71633181125"><a name="p71633181125"></a><a name="p71633181125"></a>OsFutexRequeue</p>
</td>
<td class="cellrowborder" valign="top" width="46.384638463846386%" headers="mcps1.2.4.1.3 "><p id="p151631718124"><a name="p151631718124"></a><a name="p151631718124"></a>Adjusts the position of a specified lock in the futex list.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>The futex system call and user-mode logic form a user-mode lock. Therefore, you are advised to use the locks via the user-mode POSIX APIs.
As shown in the above figure, each futex hash bucket stores the futex nodes with the same hash value linked in a futex_list. Each futex node corresponds to a suspended task. The key value of a node uniquely identifies a user-mode lock. The nodes with the same key value added to a queue_list indicate a queue of tasks blocked by the same lock.
## Available APIs
APIs of the futex module
| Category | API | Description |
| -------------- | -------------- | ------------------------------------- |
| Putting a thread to wait | OsFutexWait | Inserts a node representing a blocked thread into the futex list.|
| Waking up a thread| OsFutexWake | Wakes up a thread that is blocked by a specified lock. |
| Modifying the lock address | OsFutexRequeue | Adjusts the position of a specified lock in the futex list. |
> **NOTE**<br>
> The futex system call and user-mode logic form a user-mode lock. Therefore, you are advised to use the locks via the user-mode POSIX APIs.
# Signal
## Basic Concepts<a name="section172788254307"></a>
## Basic Concepts
Signal is a common inter-process asynchronous communication mechanism. It uses software-simulated interrupt signals. When a process needs to communicate with another process, it sends a signal to the kernel. The kernel then transfers the signal to the destination process. The destination process does not need to wait for the signal.
Signal is a common asynchronous communication mechanism between processes. It uses software-simulated interrupt signals. When a process needs to communicate with another process, it sends a signal to the kernel. The kernel transfers the signal to the target process. The target process does not need to wait for the signal.
## Working Principles<a name="section1249693812301"></a>
The following table describes the APIs available for signal operations.
## Working Principles
**Table 1** Signal operation process and APIs \(user-mode APIs\)
The following table describes the APIs for signal operations.
<a name="table1316220185211"></a>
<table><thead align="left"><tr id="row191622182021"><th class="cellrowborder" valign="top" width="27.09270927092709%" id="mcps1.2.4.1.1"><p id="p13162121815218"><a name="p13162121815218"></a><a name="p13162121815218"></a>Function</p>
</th>
<th class="cellrowborder" valign="top" width="26.49264926492649%" id="mcps1.2.4.1.2"><p id="p12162618623"><a name="p12162618623"></a><a name="p12162618623"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="46.41464146414641%" id="mcps1.2.4.1.3"><p id="p16162118427"><a name="p16162118427"></a><a name="p16162118427"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row04981218910"><td class="cellrowborder" rowspan="2" valign="top" width="27.09270927092709%" headers="mcps1.2.4.1.1 "><p id="p6462616696"><a name="p6462616696"></a><a name="p6462616696"></a>Registering the signal callback</p>
</td>
<td class="cellrowborder" valign="top" width="26.49264926492649%" headers="mcps1.2.4.1.2 "><p id="p164931214913"><a name="p164931214913"></a><a name="p164931214913"></a>signal</p>
</td>
<td class="cellrowborder" valign="top" width="46.41464146414641%" headers="mcps1.2.4.1.3 "><p id="p8504121996"><a name="p8504121996"></a><a name="p8504121996"></a>Registers the main signal entry, and registers and unregisters the callback function of a signal.</p>
</td>
</tr>
<tr id="row5449183942119"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p5450153922110"><a name="p5450153922110"></a><a name="p5450153922110"></a>sigaction</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1945083962113"><a name="p1945083962113"></a><a name="p1945083962113"></a>Same as <strong id="b1076755712371"><a name="b1076755712371"></a><a name="b1076755712371"></a>signal</strong>. This API is added with configuration options related to signal transmission. Currently, only some parameters in the <strong id="b18458105019218"><a name="b18458105019218"></a><a name="b18458105019218"></a>SIGINFO</strong> structure are supported.</p>
</td>
</tr>
<tr id="row7162101814216"><td class="cellrowborder" rowspan="5" valign="top" width="27.09270927092709%" headers="mcps1.2.4.1.1 "><p id="p37331032985"><a name="p37331032985"></a><a name="p37331032985"></a>Sending signals</p>
</td>
<td class="cellrowborder" valign="top" width="26.49264926492649%" headers="mcps1.2.4.1.2 "><p id="p816311185217"><a name="p816311185217"></a><a name="p816311185217"></a>kill</p>
</td>
<td class="cellrowborder" rowspan="5" align="left" valign="top" width="46.41464146414641%" headers="mcps1.2.4.1.3 "><p id="p161632181721"><a name="p161632181721"></a><a name="p161632181721"></a>Sends a signal to a process or sends messages to a thread in a process, and sets signal flags for threads in a process.</p>
</td>
</tr>
<tr id="row129182420243"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p149191745248"><a name="p149191745248"></a><a name="p149191745248"></a>pthread_kill</p>
</td>
</tr>
<tr id="row1026214719240"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1226313762411"><a name="p1226313762411"></a><a name="p1226313762411"></a>raise</p>
</td>
</tr>
<tr id="row05632094242"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p45643914245"><a name="p45643914245"></a><a name="p45643914245"></a>alarm</p>
</td>
</tr>
<tr id="row3241512122417"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p324211202414"><a name="p324211202414"></a><a name="p324211202414"></a>abort</p>
</td>
</tr>
<tr id="row101631818620"><td class="cellrowborder" valign="top" width="27.09270927092709%" headers="mcps1.2.4.1.1 "><p id="p146111936887"><a name="p146111936887"></a><a name="p146111936887"></a>Triggering a callback</p>
</td>
<td class="cellrowborder" valign="top" width="26.49264926492649%" headers="mcps1.2.4.1.2 "><p id="p71633181125"><a name="p71633181125"></a><a name="p71633181125"></a>None</p>
</td>
<td class="cellrowborder" valign="top" width="46.41464146414641%" headers="mcps1.2.4.1.3 "><p id="p1126941694213"><a name="p1126941694213"></a><a name="p1126941694213"></a>Triggered by a system call or an interrupt. Before the switching between the kernel mode and user mode, the specified function in user mode is entered, and the corresponding callbacks are processed. After that, the original user-mode program continues to run.</p>
</td>
</tr>
</tbody>
</table>
**Table 1** Signal APIs (user-mode APIs)
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>The signal mechanism enables communication between user-mode programs. The user-mode POSIX APIs listed in the above table are recommended.
>Register a callback function.
>```
>void *signal(int sig, void (*func)(int))(int);
>```
>a. Signal 31 is used to register the handling entry of the process callback. Repeated registration is not allowed.
>b. Signals 0 to 30 are used to register and unregister callbacks.
>Register a callback.
>```
>int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict);
>```
>You can obtain and modify the configuration of signal registration. Currently, only the **SIGINFO** options are supported. For details, see the description of the **sigtimedwait** API.
>Transmit a signal.
>a. Among the default signal-receiving behaviors, the process does not support **STOP**, **CONTINUE**, and **COREDUMP** defined in the POSIX standard.
>b. The **SIGSTOP**, **SIGKILL**, and **SIGCONT** signals cannot be shielded.
>c. If a process killed is not reclaimed by its parent process, the process becomes a zombie process.
>d. A process will not call back the signal received until the process is scheduled.
>e. When a process is killed, **SIGCHLD** is sent to its parent process. The signal sending action cannot be canceled.
>f. A process in the DELAY state cannot be woken up by a signal.
| Category | API | Description |
| ---------------- | --------------------------------------------------- | ------------------------------------------------------------ |
| Registering/Unregistering a signal callback| signal | Registers the main signal entry, and registers or unregisters a callback for a signal. |
| Registering a signal callback| sigaction | Same as **signal**. This API is added with configuration options related to signal transmission. Currently, only some parameters in the **SIGINFO** structure are supported.|
| Sending a signal | kill<br>pthread_kill<br>raise<br>alarm<br>abort | Sends a signal to a process or sends a message to a thread in a process, and sets the signal flag for a thread in a process. |
| Invoking a callback | NA | Called by a system call or an interrupt. Before the switching between the kernel mode and user mode, the callback in the specified function in user mode is processed. After that, the original user-mode program continues to run.|
> **NOTE**<br>
> The signal mechanism enables communication between user-mode programs. The user-mode POSIX APIs listed in the above table are recommended.
>
> **Registering a Callback**
>
>
> ```
> void *signal(int sig, void (*func)(int))(int);
> ```
>
> - Signal 31 is used to register the handling entry of the process callback. Repeated registration is not allowed.
>
>
> - Signals 0 to 30 are used to register and unregister callbacks.
>
>
> **Registering a Callback**
>
>
> ```
> int sigaction(int, const struct sigaction ***restrict, struct sigaction ***restrict);
> ```
>
> You can obtain and modify the configuration of signal registration. Currently, only the **SIGINFO** options are supported. For details, see the description of the **sigtimedwait** API.
>
> **Sending a Signal**
>
> - Among the default signal-receiving behaviors, the process does not support **STOP**, **COTINUE**, and **COREDUMP** defined in POSIX.
>
>
> - The **SIGSTOP**, **SIGKILL**, and **SIGCONT** signals cannot be shielded.
>
>
> - If a process killed is not reclaimed by its parent process, the process becomes a zombie process.
>
>
> - A process will not call back the signal received until the process is scheduled.
>
>
> - When a process is killed, **SIGCHLD** is sent to its parent process. The signal sending action cannot be canceled.
>
>
> - A process in the DELAY state cannot be woken up by a signal.
# LiteIPC
## Basic Concepts<a name="section1980994712918"></a>
LiteIPC is a new inter-process communication \(IPC\) mechanism provided by the OpenHarmony LiteOS-A kernel. Different from the traditional System V IPC, LiteIPC is designed for Remote Procedure Call \(RPC\). In addition, it provides APIs for the upper layer through device files, not through traditional API functions.
LiteIPC has two important concepts: ServiceManager and Service. The entire system can have one ServiceManager and multiple Services. ServiceManager is responsible for registering and unregistering Services, and managing Service access permission \(only authorized tasks can send IPC messages to corresponding Services\).
## Working Principles<a name="section849811592918"></a>
ServiceManager registers the task that needs to receive IPC messages as a Service, and sets the access permission for the Service task \(specifies the tasks that can send IPC messages to the Service\). LiteIPC maintains an IPC message queue for each Service task in kernel mode. The message queue provides the upper-layer user-mode programs with the read operation \(receiving IPC messages\) and the write operations \(sending IPC messages\) through LiteIPC device files.
## Development Guidelines<a name="section17571315171017"></a>
### Available APIs<a name="section725022011103"></a>
**Table 1** LiteIPC module APIs \(for LiteOS-A internal use only\)
<a name="table1415203765610"></a>
<table><thead align="left"><tr id="row134151837125611"><th class="cellrowborder" valign="top" width="12.85128512851285%" id="mcps1.2.4.1.1"><p id="p16415637105612"><a name="p16415637105612"></a><a name="p16415637105612"></a>Function</p>
</th>
<th class="cellrowborder" valign="top" width="29.8029802980298%" id="mcps1.2.4.1.2"><p id="p11415163718562"><a name="p11415163718562"></a><a name="p11415163718562"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="57.34573457345735%" id="mcps1.2.4.1.3"><p id="p1641533755612"><a name="p1641533755612"></a><a name="p1641533755612"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row0415737175610"><td class="cellrowborder" valign="top" width="12.85128512851285%" headers="mcps1.2.4.1.1 "><p id="p8866127195914"><a name="p8866127195914"></a><a name="p8866127195914"></a>Module initialization</p>
</td>
<td class="cellrowborder" valign="top" width="29.8029802980298%" headers="mcps1.2.4.1.2 "><p id="p58621910185914"><a name="p58621910185914"></a><a name="p58621910185914"></a>OsLiteIpcInit</p>
</td>
<td class="cellrowborder" valign="top" width="57.34573457345735%" headers="mcps1.2.4.1.3 "><p id="p48623102592"><a name="p48623102592"></a><a name="p48623102592"></a>Initializes the LiteIPC module.</p>
</td>
</tr>
<tr id="row1213865218584"><td class="cellrowborder" rowspan="3" valign="top" width="12.85128512851285%" headers="mcps1.2.4.1.1 "><p id="p1219312239566"><a name="p1219312239566"></a><a name="p1219312239566"></a>IPC message memory pool</p>
</td>
<td class="cellrowborder" valign="top" width="29.8029802980298%" headers="mcps1.2.4.1.2 "><p id="p20862510115911"><a name="p20862510115911"></a><a name="p20862510115911"></a>LiteIpcPoolInit</p>
</td>
<td class="cellrowborder" valign="top" width="57.34573457345735%" headers="mcps1.2.4.1.3 "><p id="p1886211011599"><a name="p1886211011599"></a><a name="p1886211011599"></a>Initializes the IPC message memory pool of processes.</p>
</td>
</tr>
<tr id="row3231257145813"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p3313428135414"><a name="p3313428135414"></a><a name="p3313428135414"></a>LiteIpcPoolReInit</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p586261085913"><a name="p586261085913"></a><a name="p586261085913"></a>Re-initializes the IPC message memory pool of processes.</p>
</td>
</tr>
<tr id="row73651459105815"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p464344145411"><a name="p464344145411"></a><a name="p464344145411"></a>LiteIpcPoolDelete</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p555221518598"><a name="p555221518598"></a><a name="p555221518598"></a>Releases the IPC message memory pool of processes.</p>
</td>
</tr>
<tr id="row178321454145812"><td class="cellrowborder" valign="top" width="12.85128512851285%" headers="mcps1.2.4.1.1 "><p id="p19527545175517"><a name="p19527545175517"></a><a name="p19527545175517"></a>Service management</p>
</td>
<td class="cellrowborder" valign="top" width="29.8029802980298%" headers="mcps1.2.4.1.2 "><p id="p756845455415"><a name="p756845455415"></a><a name="p756845455415"></a>LiteIpcRemoveServiceHandle</p>
</td>
<td class="cellrowborder" valign="top" width="57.34573457345735%" headers="mcps1.2.4.1.3 "><p id="p1555261595915"><a name="p1555261595915"></a><a name="p1555261595915"></a>Deletes the specified Service.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>LiteIPC module APIs are used for LiteOS-A internal use only.
## Basic Concepts
LiteIPC is a new inter-process communication (IPC) mechanism provided by the OpenHarmony LiteOS-A kernel. Different from the traditional System V IPC, LiteIPC is designed for Remote Procedure Call (RPC). In addition, it provides APIs for the upper layer through device files, not through traditional API functions.
LiteIPC has two important concepts: ServiceManager and Service. The entire system can have one ServiceManager and multiple Services.
ServiceManager provides the following functions:
- Registers and deregisters services.
- Manages the access permission of services. Only authorized tasks can send IPC messages to the service.
## Working Principles
ServiceManager registers the task that needs to receive IPC messages as a Service, and sets the access permission for the Service task (specifies the tasks that can send IPC messages to the Service).
LiteIPC maintains an IPC message queue for each Service task in kernel mode. The message queue provides the upper-layer user-mode programs with the read operation (receiving IPC messages) and the write operations (sending IPC messages) through LiteIPC device files.
## Development Guidelines
### Available APIs
**Table 1** APIs of the LiteIPC module (applicable to LiteOS-A only)
| Category | API Description |
| ------------- | ------------------------------------------------------------ |
| Module initialization | **OsLiteIpcInit**: initializes the LiteIPC module. |
| IPC message memory pool| - **LiteIpcPoolInit**: initializes the IPC message memory pool of a process.<br>- **LiteIpcPoolReInit**: reinitializes the IPC message memory pool of a process.<br>- **LiteIpcPoolDelete**: releases the IPC message memory pool of a process. |
| Service management | **LiteIpcRemoveServiceHandle**: deletes a service. |
> **NOTE**<br>
> The APIs of the LiteIPC module are dedicated for LiteOS-A internal use only.
# Dynamic Loading and Linking
## Basic Concepts<a name="section208951139453"></a>
## Basic Concepts
The OpenHarmony dynamic loading and linking mechanism includes a kernel loader and a dynamic linker. The kernel loader loads application programs and the dynamic linker. The dynamic linker loads the shared library on which the application programs depend, and performs symbol relocation for the application programs and shared libraries. Compared with static linking, dynamic linking is a mechanism for delaying the linking of applications and dynamic libraries to run time.
**Advantages of Dynamic Linking**
1. Dynamic linking allows multiple applications to share code. The minimum loading unit is page. Dynamic linking saves disk and memory space than static linking.
2. When a shared library is upgraded, the new shared library overwrites the earlier version \(the APIs of the shared library are downward compatible\). You do not need to re-link the shared library.
3. The loading address can be randomized to prevent attacks and ensure security.
- Dynamic linking allows multiple applications to share code. The minimum loading unit is page. Dynamic linking saves disk and memory space than static linking.
- When a shared library is upgraded, the new shared library overwrites the earlier version (the APIs of the shared library are downward compatible). You do not need to re-link the shared library.
- The loading address can be randomized to prevent attacks and ensure security.
## Working Principles
## Working Principles<a name="section14140155320511"></a>
**Figure 1** Dynamic loading process
**Figure 1** Dynamic loading process<a name="fig1797764116422"></a>
![](figures/dynamic-loading-process.png "dynamic-loading-process")
1. The kernel maps the **PT\_LOAD** section in the ELF file of the application to the process space. For files of the ET\_EXEC type, fixed address mapping is performed based on **p\_vaddr** in the **PT\_LOAD** section. For files of the ET\_DYN type \(position-independent executable programs, obtained through the compile option **-fPIE**\), the kernel selects the **base** address via **mmap** for mapping \(load\_addr = base + p\_vaddr\).
2. If the application is statically linked \(static linking does not support the compile option **-fPIE**\), after the stack information is set, the system redirects to the address specified by **e\_entry** in the ELF file of the application and runs the application. If the program is dynamically linked, the application ELF file contains the **PT\_INTERP** section, which stores the dynamic linker path information \(ET\_DYN type\). The dynamic linker of musl is a part of the **libc-musl.so**. The entry of **libc-musl.so** is the entry of the dynamic linker. The kernel selects the **base** address for mapping via the **mmap** API, sets the stack information, redirects to the **base + e\_entry** \(entry of the dynamic linker\) address, and runs the dynamic linker.
3. The dynamic linker bootstraps and searches for all shared libraries on which the application depends, relocates the imported symbols, and finally redirects to the **e\_entry** \(or **base + e\_entry**\) of the application to run the application.
1. The kernel maps the **PT_LOAD** section in the ELF file of the application to the process space. For files of the ET_EXEC type, fixed address mapping is performed based on **p_vaddr** in the **PT_LOAD** section. For files of the ET_DYN type (position-independent executable programs, obtained through **-fPIE**), the kernel selects the **base** address via **mmap** for mapping (load_addr = base + p_vaddr).
2. If the application is statically linked (static linking does not support **-fPIE**), after the stack information is set, the system redirects to the address specified by **e_entry** in the ELF file of the application and runs the application. If the program is dynamically linked, the application ELF file contains the **PT_INTERP** section, which stores the dynamic linker path information (ET_DYN type). The dynamic linker of musl is a part of the **libc-musl.so**. The entry of **libc-musl.so** is the entry of the dynamic linker. The kernel selects the **base** address for mapping via the **mmap** API, sets the stack information, redirects to the **base + e_entry** (entry of the dynamic linker) address, and runs the dynamic linker.
3. The dynamic linker bootstraps and searches for all shared libraries on which the application depends, relocates the imported symbols, and finally redirects to the **e_entry** (or **base + e_entry**) of the application to run the application.
**Figure 2** Program execution process
**Figure 2** Program execution process<a name="fig17879151310447"></a>
![](figures/program-execution-process.png "program-execution-process")
1. The loader and linker call **mmap** to map the **PT\_LOAD** section.
2. The kernel calls **map\_pages** to search for and map the existing PageCache.
3. If there is no physical memory for mapping in the virtual memory region during program execution, the system triggers a page missing interrupt, which allows the ELF file to be read into the physical memory and adds the memory block to the pagecache.
4. Map the physical memory blocks of the file read to the virtual address region.
5. The program continues to run.
## Development Guidelines<a name="section133501496612"></a>
### Available APIs<a name="section874113201669"></a>
**Table 1** APIs of the kernel loader module
<a name="table1415203765610"></a>
<table><thead align="left"><tr id="row134151837125611"><th class="cellrowborder" valign="top" width="12.85128512851285%" id="mcps1.2.4.1.1"><p id="p16415637105612"><a name="p16415637105612"></a><a name="p16415637105612"></a>Function</p>
</th>
<th class="cellrowborder" valign="top" width="29.8029802980298%" id="mcps1.2.4.1.2"><p id="p11415163718562"><a name="p11415163718562"></a><a name="p11415163718562"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="57.34573457345735%" id="mcps1.2.4.1.3"><p id="p1641533755612"><a name="p1641533755612"></a><a name="p1641533755612"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row0415737175610"><td class="cellrowborder" valign="top" width="12.85128512851285%" headers="mcps1.2.4.1.1 "><p id="p8866127195914"><a name="p8866127195914"></a><a name="p8866127195914"></a>Module initialization</p>
</td>
<td class="cellrowborder" valign="top" width="29.8029802980298%" headers="mcps1.2.4.1.2 "><p id="p58621910185914"><a name="p58621910185914"></a><a name="p58621910185914"></a>LOS_DoExecveFile</p>
</td>
<td class="cellrowborder" valign="top" width="57.34573457345735%" headers="mcps1.2.4.1.3 "><p id="p48623102592"><a name="p48623102592"></a><a name="p48623102592"></a>Executes the specified user program based on the input parameters.</p>
</td>
</tr>
</tbody>
</table>
### How to Develop<a name="section196712561563"></a>
The kernel cannot directly call the **LOS\_DoExecveFile** API to start a new process. This API is generally called through the **exec\(\)** API to create a new process using the system call mechanism.
1. The loader and linker call **mmap** to map the **PT_LOAD** section.
2. The kernel calls **map_pages** to search for and map the existing PageCache.
3. If there is no physical memory for mapping in the virtual memory region during program execution, the system triggers a page missing interrupt, which allows the ELF file to be read into the physical memory and adds the memory block to the pagecache.
4. Map the physical memory blocks of the file read to the virtual address region.
5. The program continues to run.
## Development Guidelines
### Available APIs
**Table 1** API of the kernel loader module
| Category | API | Description |
| ---------- | ---------------- | -------------------------------- |
| Starting initialization| LOS_DoExecveFile | Executes the specified user program based on the input parameters.|
### How to Develop
The kernel cannot directly call the **LOS_DoExecveFile** API to start a new process. This API is generally called through the **exec()** API to create a new process using the system call mechanism.
# Virtual Dynamic Shared Object
## Basic Concepts<a name="section174577181688"></a>
Different from a common dynamic shared library, which stores its .so files in the file system, the virtual dynamic shared object \(VDSO\) has its .so files stored in the system image. The kernel determines the .so files needed and provides them to the application program. That is why the VDSO is called a virtual dynamic shared library.
## Basic Concepts
The VDSO mechanism allows OpenHarmony user-mode programs to quickly obtain kernel-related data. It can accelerate certain system calls and implement quick read of non-sensitive data \(hardware and software configuration\).
Different from a common dynamic shared library, which stores its .so files in the file system, the virtual dynamic shared object (VDSO) has its .so files stored in the system image. The kernel determines the .so files needed and provides them to the application program. That is why the VDSO is called a virtual dynamic shared library.
## Working Principles<a name="section546363114810"></a>
The VDSO mechanism allows OpenHarmony user-mode programs to quickly obtain kernel-related data. It can accelerate certain system calls and implement quick read of non-sensitive data (hardware and software configuration).
The VDSO can be regarded as a section of memory \(read-only\) maintained by the kernel and mapped to the address space of the user-mode applications. By linking **vdso.so**, the applications can directly access this mapped memory instead of invoking system calls, accelerating application execution.
## Working Principles
The VDSO can be regarded as a section of memory (read-only) maintained by the kernel and mapped to the address space of the user-mode applications. By linking **vdso.so**, the applications can directly access this mapped memory instead of invoking system calls, accelerating application execution.
VDSO can be divided into:
- Data page: provides the kernel-time data mapped to the user process.
- Code page: provides the logic for shielding system calls.
- Data page: provides the kernel-time data mapped to the user process.
- Code page: provides the logic for shielding system calls.
**Figure 1** VDSO system design
**Figure 1** VDSO system design<a name="fig1986131094711"></a>
![](figures/vdso-system-design.jpg "vdso-system-design")
The VDSO mechanism involves the following steps:
......@@ -30,7 +33,7 @@ The VDSO mechanism involves the following steps:
5. Binds the VDSO symbols when the user program creates dynamic linking.
6. The VDSO code page intercepts specific system calls \(for example, **clock\_gettime\(CLOCK\_REALTIME\_COARSE, &ts\)**\).
6. The VDSO code page intercepts specific system calls (for example, **clock_gettime(CLOCK_REALTIME_COARSE, &amp;ts)**).
7. The VDSO code page allows direct read of the mapped VDSO data page rather than invoking a system call.
......@@ -38,7 +41,10 @@ The VDSO mechanism involves the following steps:
9. Returns the data obtained from the VDSO data page to the user program.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>- The VDSO mechanism supports the **CLOCK\_REALTIME\_COARSE** and **CLOCK\_MONOTONIC\_COARSE** functions of the **clock\_gettime** API in the LibC library. For details about how to use the **clock\_gettime** API, see the POSIX standard. You can call **clock\_gettime\(CLOCK\_REALTIME\_COARSE, &ts\)** or **clock\_gettime\(CLOCK\_MONOTONIC\_COARSE, &ts\)** of the LibC library to use the VDSO.
>- When VDSO is used, the time precision is the same as that of the tick interrupt of the system. The VDSO mechanism is applicable to the scenario where there is no demand for high time precision and **clock\_gettime** or **gettimeofday** is frequently triggered in a short period of time. The VDSO mechanism is not recommended for the system demanding high time precision.
> **NOTE**<br>
>
> - The VDSO mechanism supports the **CLOCK_REALTIME_COARSE** and **CLOCK_MONOTONIC_COARSE** functions of the **clock_gettime** API in the LibC library. For details about how to use the **clock_gettime** API, see the POSIX standard.
>
> - You can call **clock_gettime(CLOCK_REALTIME_COARSE, &amp;ts)** or **clock_gettime(CLOCK_MONOTONIC_COARSE, &amp;ts)** of the Libc library to use the VDSO.
>
> - When VDSO is used, the time precision is the same as that of the tick interrupt of the system. The VDSO mechanism is applicable to the scenario where there is no demand for high time precision and **clock_gettime** or **gettimeofday** is frequently triggered in a short period of time. The VDSO mechanism is not recommended for the system demanding high time precision.
# cpup
## Command Function<a name="section1842161614217"></a>
## Command Function
This command is used to query the CPU usage \(CPU percent\) of the system.
This command is used to query the CPU percent (CPUP) of the system.
## Syntax<a name="section5629527427"></a>
cpup \[_mode_\] \[_taskID_\]
## Syntax
## Parameters<a name="section133651361023"></a>
cpup [_mode_] [_taskID_]
**Table 1** Parameter description
<a name="table3774mcpsimp"></a>
<table><thead align="left"><tr id="row3780mcpsimp"><th class="cellrowborder" valign="top" width="16%" id="mcps1.2.4.1.1"><p id="p3782mcpsimp"><a name="p3782mcpsimp"></a><a name="p3782mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="56.99999999999999%" id="mcps1.2.4.1.2"><p id="p3784mcpsimp"><a name="p3784mcpsimp"></a><a name="p3784mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p3786mcpsimp"><a name="p3786mcpsimp"></a><a name="p3786mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row3787mcpsimp"><td class="cellrowborder" valign="top" width="16%" headers="mcps1.2.4.1.1 "><p id="p3789mcpsimp"><a name="p3789mcpsimp"></a><a name="p3789mcpsimp"></a>mode</p>
</td>
<td class="cellrowborder" valign="top" width="56.99999999999999%" headers="mcps1.2.4.1.2 "><a name="ul1530071303413"></a><a name="ul1530071303413"></a><ul id="ul1530071303413"><li>Displays the CPU usage of the system within the last 10 seconds by default.</li><li><strong id="b13709113084810"><a name="b13709113084810"></a><a name="b13709113084810"></a>0</strong>: displays the CPU usage within the last 10 seconds.</li><li><strong id="b10788133319480"><a name="b10788133319480"></a><a name="b10788133319480"></a>1</strong>: displays the CPU usage within the last 1 second.</li><li>Other value: displays the total CPU usage since the system is started.</li></ul>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3794mcpsimp"><a name="p3794mcpsimp"></a><a name="p3794mcpsimp"></a>[0,0xFFFFFFFF]</p>
</td>
</tr>
<tr id="row3795mcpsimp"><td class="cellrowborder" valign="top" width="16%" headers="mcps1.2.4.1.1 "><p id="p3797mcpsimp"><a name="p3797mcpsimp"></a><a name="p3797mcpsimp"></a>taskID</p>
</td>
<td class="cellrowborder" valign="top" width="56.99999999999999%" headers="mcps1.2.4.1.2 "><p id="p3799mcpsimp"><a name="p3799mcpsimp"></a><a name="p3799mcpsimp"></a>Specifies the task ID.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3802mcpsimp"><a name="p3802mcpsimp"></a><a name="p3802mcpsimp"></a>[0,0xFFFFFFFF]</p>
</td>
</tr>
</tbody>
</table>
## Parameters
## Usage<a name="section156611948521"></a>
**Table 1** Parameter description
- If no parameter is specified, the CPU usage of the system within the last 10 seconds is displayed.
- If only **mode** is specified, the CPU usage within the specified period is displayed.
- If both **mode** and **taskID** are specified, the CPU usage of the specified task within the given period is displayed.
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| mode | Displays the CPUP of the system within the last 10 seconds by default.<br>- **0**: displays the CPUP within the last 10 seconds.<br>- **1**: displays the CPUP within the last 1 second.<br>- Other numbers: display the total CPUP since the system starts.| [0, 0xFFFFFFFF] |
| taskID | Specifies the task ID.| [0, 0xFFFFFFFF] |
## Example<a name="section68501605319"></a>
Run **cpup 1 5**.
## Usage Guidelines
## Output<a name="section19871522144219"></a>
- If no parameter is specified, the CPU usage of the system within the last 10 seconds is displayed.
- If only **mode** is specified, the CPU usage within the specified period is displayed.
- If both **mode** and **taskID** are specified, the CPU usage of the specified task within the given period is displayed.
## Example
Run **cpup 1 5**.
## Output
CPU usage of task 5 in the last one second:
......@@ -58,4 +44,3 @@ OHOS # cpup 1 5pid 5
CpuUsage in 1s: 0.0
```
# date
## Command Function<a name="section56472016338"></a>
## Command Function
This command is used to query the system date and time.
## Syntax<a name="section16635112512316"></a>
- date
- date --help
- date +\[_Format_\]
- date -u
## Parameters<a name="section15896030039"></a>
**Table 1** Parameter description
<a name="table3825mcpsimp"></a>
<table><thead align="left"><tr id="row3831mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p3833mcpsimp"><a name="p3833mcpsimp"></a><a name="p3833mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.4.1.2"><p id="p3835mcpsimp"><a name="p3835mcpsimp"></a><a name="p3835mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="28.999999999999996%" id="mcps1.2.4.1.3"><p id="p3837mcpsimp"><a name="p3837mcpsimp"></a><a name="p3837mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row14667120409"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p5628123402"><a name="p5628123402"></a><a name="p5628123402"></a>--help</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.4.1.2 "><p id="p1162201234017"><a name="p1162201234017"></a><a name="p1162201234017"></a>Displays help information.</p>
</td>
<td class="cellrowborder" valign="top" width="28.999999999999996%" headers="mcps1.2.4.1.3 "><p id="p11621412194011"><a name="p11621412194011"></a><a name="p11621412194011"></a>N/A</p>
</td>
</tr>
<tr id="row1566191264014"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p186211254017"><a name="p186211254017"></a><a name="p186211254017"></a>+Format</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.4.1.2 "><p id="p26216124407"><a name="p26216124407"></a><a name="p26216124407"></a>Prints the date and time in the specified <strong id="b115041849185916"><a name="b115041849185916"></a><a name="b115041849185916"></a>Format</strong>.</p>
</td>
<td class="cellrowborder" valign="top" width="28.999999999999996%" headers="mcps1.2.4.1.3 "><p id="p46251220409"><a name="p46251220409"></a><a name="p46251220409"></a>Placeholders listed in <strong id="b36588246116"><a name="b36588246116"></a><a name="b36588246116"></a>--help</strong></p>
</td>
</tr>
<tr id="row1766111218401"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p146291274011"><a name="p146291274011"></a><a name="p146291274011"></a>-u</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.4.1.2 "><p id="p136291219403"><a name="p136291219403"></a><a name="p136291219403"></a>Displays UTC instead of the current time zone.</p>
</td>
<td class="cellrowborder" valign="top" width="28.999999999999996%" headers="mcps1.2.4.1.3 "><p id="p5628129407"><a name="p5628129407"></a><a name="p5628129407"></a>N/A</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section116361036636"></a>
- If no parameter is specified, the system UTC date and time are displayed by default.
- The **--help**, **+Format**, and **-u** parameters are mutually exclusive.
- Currently, this command cannot be used to set the time or date.
## Example<a name="section021711411237"></a>
Run **date +%Y--%m--%d**.
## Output<a name="section17950184414312"></a>
## Syntax
- date
- date --help
- date +[_Format_]
- date -u
## Parameters
**Table 1** Parameter description
| Parameter | Description | Value Range |
| ------- | ------------------------------ | ---------------------- |
| --help | Displays help information. | N/A |
| +Format | Prints the date and time in the specified format.| Placeholders listed in **--help**|
| -u | Displays UTC (not the current time zone). | N/A |
## Usage Guidelines
- If no parameter is specified, the system date and time in UTC format are displayed by default.
- The **--help**, **+Format**, and **-u** parameters are mutually exclusive.
- Currently, this command cannot be used to set the time or date.
## Note
The shell does not support **date -u**. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
## Example
Run **date +%Y--%m--%d**.
## Output
System date in the specified format:
```
OHOS:/$ date +%Y--%m--%d
1970--01--01
```
# dmesg
## Command Function<a name="section4643204919313"></a>
## Command Function
This command is used to display system boot and running information.
## Syntax<a name="section6553153635"></a>
## Syntax
dmesg
dmesg \[_-c/-C/-D/-E/-L/-U_\]
dmesg -s \[_size_\]
dmesg -l \[_level_\]
dmesg \> \[_fileA_\]
## Parameters<a name="section208971157532"></a>
**Table 1** Parameter description
<a name="table3900mcpsimp"></a>
<table><thead align="left"><tr id="row3906mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p3908mcpsimp"><a name="p3908mcpsimp"></a><a name="p3908mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p3910mcpsimp"><a name="p3910mcpsimp"></a><a name="p3910mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p3912mcpsimp"><a name="p3912mcpsimp"></a><a name="p3912mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row3913mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p3915mcpsimp"><a name="p3915mcpsimp"></a><a name="p3915mcpsimp"></a>-c</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p3917mcpsimp"><a name="p3917mcpsimp"></a><a name="p3917mcpsimp"></a>Prints content in the buffer and clears the buffer.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3919mcpsimp"><a name="p3919mcpsimp"></a><a name="p3919mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row3920mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p3922mcpsimp"><a name="p3922mcpsimp"></a><a name="p3922mcpsimp"></a>-C</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p3924mcpsimp"><a name="p3924mcpsimp"></a><a name="p3924mcpsimp"></a>Clears the buffer.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3926mcpsimp"><a name="p3926mcpsimp"></a><a name="p3926mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row3927mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p3929mcpsimp"><a name="p3929mcpsimp"></a><a name="p3929mcpsimp"></a>-D/-E</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p3931mcpsimp"><a name="p3931mcpsimp"></a><a name="p3931mcpsimp"></a>Disables or enables printing to the console.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3933mcpsimp"><a name="p3933mcpsimp"></a><a name="p3933mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row3934mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p3936mcpsimp"><a name="p3936mcpsimp"></a><a name="p3936mcpsimp"></a>-L/-U</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p3938mcpsimp"><a name="p3938mcpsimp"></a><a name="p3938mcpsimp"></a>Disables or enables printing via the serial port.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3940mcpsimp"><a name="p3940mcpsimp"></a><a name="p3940mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row3941mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p3943mcpsimp"><a name="p3943mcpsimp"></a><a name="p3943mcpsimp"></a>-s size</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p3945mcpsimp"><a name="p3945mcpsimp"></a><a name="p3945mcpsimp"></a>Sets the size of the buffer.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3947mcpsimp"><a name="p3947mcpsimp"></a><a name="p3947mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row3948mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p3950mcpsimp"><a name="p3950mcpsimp"></a><a name="p3950mcpsimp"></a>-l level</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p3952mcpsimp"><a name="p3952mcpsimp"></a><a name="p3952mcpsimp"></a>Sets the buffering level.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3954mcpsimp"><a name="p3954mcpsimp"></a><a name="p3954mcpsimp"></a>0 - 5</p>
</td>
</tr>
<tr id="row3955mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p3957mcpsimp"><a name="p3957mcpsimp"></a><a name="p3957mcpsimp"></a>&gt; fileA</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p717417317512"><a name="p717417317512"></a><a name="p717417317512"></a>Writes the content in the buffer to the specified file.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3961mcpsimp"><a name="p3961mcpsimp"></a><a name="p3961mcpsimp"></a>N/A</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section213115219413"></a>
- This command depends on **LOSCFG\_SHELL\_DMESG**. Before using this command, select **Enable Shell dmesg** on **menuconfig**.
Debug ---\> Enable a Debug Version ---\> Enable Shell ---\> Enable Shell dmesg
- If no parameter is specified, all content in the buffer is printed.
- The parameters followed by hyphens \(-\) are mutually exclusive.
1. Before writing content to a file, ensure that the file system has been mounted.
2. Disabling the serial port printing will adversely affect shell. You are advised to set up a connection using Telnet before disabling the serial port.
## Example<a name="section13736564418"></a>
Run **dmesg\> dmesg.log**.
## Output<a name="section194005101413"></a>
Writing the content in the buffer to the **dmesg.log** file:
dmesg [_-c/-C/-D/-E/-L/-U_]
dmesg -s [_size_]
dmesg -l [_level_]
dmesg &gt; [_fileA_]
## Parameters
**Table 1** Parameter description
| Parameter | Description | Value Range |
| --------------- | ---------------------------------------- | --------------- |
| -c | Prints content in the buffer and clears the buffer. | N/A |
| -C | Clears the buffer. | N/A |
| -D/-E | Disables or enables printing to the console. | N/A |
| -L/-U | Disables or enables printing via the serial port. | N/A |
| -s&nbsp;size | Sets the size of the buffer. size specifies the buffer size to set.| N/A |
| -l&nbsp;level | Sets the buffering level. | [0, 5] |
| &gt;&nbsp;fileA | Writes the content in the buffer to a file. | N/A |
## Usage Guidelines
- This command can be used only after **LOSCFG_SHELL_DMESG** is enabled. To enable **LOSCFG_SHELL_DMESG**, run the **make menuconfig** command in **kernel/liteos_a**. In the displayed dialog box, locate the **Debug** option and set **Enable Shell dmesg** to **Yes**.
Debug ---&gt; Enable a Debug Version ---&gt; Enable Shell ---&gt; Enable Shell dmesg
- If no parameter is specified, all content in the buffer is printed.
- The parameters followed by hyphens (-) are mutually exclusive.
1. Before writing content to a file, ensure that the file system has been mounted.
2. Disabling the serial port printing will adversely affect shell. You are advised to set up a connection using Telnet before disabling the serial port.
## Example
Run **dmesg> dmesg.log**.
## Output
Write the content in the buffer to the **dmesg.log** file.
```
OHOS # dmesg > dmesg.log
Dmesg write log to dmesg.log success
```
# exec
## Command Function<a name="section4643204919313"></a>
## Command Function
This command is a built-in shell command used to execute user-mode programs.
This command is a built-in shell command used to execute basic user-mode programs.
## Syntax<a name="section6553153635"></a>
exec <_executable-file_\>
## Syntax
## Parameters<a name="section208971157532"></a>
exec &lt;*executable-file*&gt;
**Table 1** Parameter description
<a name="table3900mcpsimp"></a>
<table><thead align="left"><tr id="row3906mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p3908mcpsimp"><a name="p3908mcpsimp"></a><a name="p3908mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p3910mcpsimp"><a name="p3910mcpsimp"></a><a name="p3910mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p3912mcpsimp"><a name="p3912mcpsimp"></a><a name="p3912mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row3913mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p3915mcpsimp"><a name="p3915mcpsimp"></a><a name="p3915mcpsimp"></a>executable-file</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p3917mcpsimp"><a name="p3917mcpsimp"></a><a name="p3917mcpsimp"></a>Indicates a valid executable file.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3919mcpsimp"><a name="p3919mcpsimp"></a><a name="p3919mcpsimp"></a>N/A</p>
</td>
</tr>
</tbody>
</table>
## Parameters
## Usage<a name="section213115219413"></a>
**Table 1** Parameter description
| Parameter | Description |
| --------------- | ------------------ |
| executable-file | Specifies a valid executable file.|
## Usage Guidelines
Currently, this command supports only valid binary programs. The programs are successfully executed and then run in the background by default. However, the programs share the same device with the shell. As a result, the output of the programs and the shell may be interlaced.
## Example<a name="section13736564418"></a>
Example:
## Example
Run **exec helloworld**.
Run **exec helloworld**.
## Output
## Output<a name="section194005101413"></a>
```
OHOS # exec helloworld
OHOS # hello world!
```
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>After the executable file is executed, the prompt **OHOS \#** is printed first. The shell **exec** command is executed in the background, causing the prompt to be printed in advance.
> **NOTE**<br>
> After the executable file is executed, the prompt **OHOS #** is printed first. The shell **exec** command is executed in the background, causing the prompt to be printed in advance.
# free
## Command Function<a name="section175151514841"></a>
## Command Function
This command is used to display the memory usage in the system.
## Syntax<a name="section8488721749"></a>
free \[_-b | -k | -m | -g | -t_\]
## Parameters<a name="section27272181949"></a>
**Table 1** Parameter description
<a name="table110mcpsimp"></a>
<table><thead align="left"><tr id="row116mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p118mcpsimp"><a name="p118mcpsimp"></a><a name="p118mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p120mcpsimp"><a name="p120mcpsimp"></a><a name="p120mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p122mcpsimp"><a name="p122mcpsimp"></a><a name="p122mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row1250317052114"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p44861016218"><a name="p44861016218"></a><a name="p44861016218"></a>No parameter</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p64861302212"><a name="p64861302212"></a><a name="p64861302212"></a>Displays the memory usage in bytes.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p1248619010215"><a name="p1248619010215"></a><a name="p1248619010215"></a>N/A</p>
</td>
</tr>
<tr id="row2503160182110"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p1948618017215"><a name="p1948618017215"></a><a name="p1948618017215"></a>--help/-h</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p1648617012214"><a name="p1648617012214"></a><a name="p1648617012214"></a>Displays the parameters supported by the <strong id="b1247315411335"><a name="b1247315411335"></a><a name="b1247315411335"></a>free</strong> command.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p11486205219"><a name="p11486205219"></a><a name="p11486205219"></a>N/A</p>
</td>
</tr>
<tr id="row150318082111"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p164861709216"><a name="p164861709216"></a><a name="p164861709216"></a>-b</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p54864013214"><a name="p54864013214"></a><a name="p54864013214"></a>Displays the memory usage in bytes.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p124862014218"><a name="p124862014218"></a><a name="p124862014218"></a>N/A</p>
</td>
</tr>
<tr id="row750330162116"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p1848615072110"><a name="p1848615072110"></a><a name="p1848615072110"></a>-k</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p1648670192120"><a name="p1648670192120"></a><a name="p1648670192120"></a>Displays the memory usage in KiB.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p124861301216"><a name="p124861301216"></a><a name="p124861301216"></a>N/A</p>
</td>
</tr>
<tr id="row105021082114"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p20486100122114"><a name="p20486100122114"></a><a name="p20486100122114"></a>-m</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p134869022114"><a name="p134869022114"></a><a name="p134869022114"></a>Displays the memory usage in MiB.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p124868015219"><a name="p124868015219"></a><a name="p124868015219"></a>N/A</p>
</td>
</tr>
<tr id="row95021909216"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p114861408218"><a name="p114861408218"></a><a name="p114861408218"></a>-g</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p348680122118"><a name="p348680122118"></a><a name="p348680122118"></a>Displays the memory usage in GiB.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p64866011217"><a name="p64866011217"></a><a name="p64866011217"></a>N/A</p>
</td>
</tr>
<tr id="row125026092116"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p19486101218"><a name="p19486101218"></a><a name="p19486101218"></a>-t</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p18486140132118"><a name="p18486140132118"></a><a name="p18486140132118"></a>Displays the memory usage in TiB.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p048620142111"><a name="p048620142111"></a><a name="p048620142111"></a>N/A</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section148661259410"></a>
None
## Example<a name="section68081530242"></a>
Run **free**, **free -k**, and **free -m**, respectively.
## Output<a name="section171235517543"></a>
## Syntax
free [_-b | -k | -m | -g | -t_]
## Parameters
**Table 1** Parameter description
| Parameter| Description |
| -------- | -------- |
| No parameter| Displays the memory usage in bytes.|
| --help/-h | Displays the parameters supported by the **free** command.|
| -b | Displays the memory usage in bytes.|
| -k | Display the memory waterline in KiB.|
| -m | Display the memory waterline in MiB.|
| -g | Displays the memory usage in GiB.|
| -t | Displays the memory usage in TiB.|
## Usage Guidelines
None.
## Example
Run **free**, **free -k**, and **free -m**, respectively.
## Output
```
OHOS:/$ free
......@@ -101,40 +57,13 @@ Mem: 2 2 0 0 0
Swap: 0 0 0
```
**Table 2** Output
<a name="table633mcpsimp"></a>
<table><thead align="left"><tr id="row638mcpsimp"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p640mcpsimp"><a name="p640mcpsimp"></a><a name="p640mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p642mcpsimp"><a name="p642mcpsimp"></a><a name="p642mcpsimp"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row3746215112211"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p57373157224"><a name="p57373157224"></a><a name="p57373157224"></a>total</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1737315202218"><a name="p1737315202218"></a><a name="p1737315202218"></a>Total size of the dynamic memory pool</p>
</td>
</tr>
<tr id="row16746161582219"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1173731512215"><a name="p1173731512215"></a><a name="p1173731512215"></a>used</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p197376156222"><a name="p197376156222"></a><a name="p197376156222"></a>Size of the used memory</p>
</td>
</tr>
<tr id="row174661542216"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p8737141519228"><a name="p8737141519228"></a><a name="p8737141519228"></a>free</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p97371915142218"><a name="p97371915142218"></a><a name="p97371915142218"></a>Size of the unallocated memory</p>
</td>
</tr>
<tr id="row1274520152227"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1073821542210"><a name="p1073821542210"></a><a name="p1073821542210"></a>shared</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1773801514223"><a name="p1773801514223"></a><a name="p1773801514223"></a>Size of the shared memory</p>
</td>
</tr>
<tr id="row07452153229"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p773811512229"><a name="p773811512229"></a><a name="p773811512229"></a>buffers</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p157381015192216"><a name="p157381015192216"></a><a name="p157381015192216"></a>Size of the buffer</p>
</td>
</tr>
</tbody>
</table>
**Table 2** Output description
| Parameter| Description|
| -------- | -------- |
| total | Total size of the dynamic memory pool.|
| used | Size of the used memory.|
| free | Size of the unallocated memory.|
| shared | Size of the shared memory.|
| buffers | Size of the buffer.|
# help
## Command Function<a name="section991211345413"></a>
## Command Function
This command is used to display all commands in the OS and some Toybox commands.
## Syntax<a name="section19103204016410"></a>
## Syntax
help
## Parameters<a name="section1533416233432"></a>
None
## Parameters
None.
## Usage<a name="section4156445417"></a>
## Usage Guidelines
You can run **help** to display all commands in the current OS.
You can run **help** to display all commands in the current OS.
## Example<a name="section12776124712417"></a>
Run **help**.
## Example
## Output<a name="section092662412544"></a>
Run **help**.
## Output
All commands in the system:
```
After shell prompt "OHOS # ":
Use `<cmd> [args ...]` to run built-in shell commands listed above.
Use `exec <cmd> [args ...]` or `./<cmd> [args ...]` to run external commands.
OHOS:/$ help
*******************shell commands:*************************
***shell commands:*
arp cat cat_logmpp cd chgrp chmod
chown cp cpup date dhclient dmesg
dns format free help hi3881 hwi
......@@ -44,11 +51,10 @@ watch writeproc
After shell prompt "OHOS # ":
Use `<cmd> [args ...]` to run built-in shell commands listed above.
Use `exec <cmd> [args ...]` or `./<cmd> [args ...]` to run external commands.
*******************toybox commands:************************
***toybox commands:
chgrp chmod chown cp date du free help ifconfig kill ls mkdir mount
mv ping ps reboot rm rmdir top touch umount uname
Use `toybox help [command]` to show usage information for a specific command.
Use `shell` to enter interactive legacy shell.
Use `alias` to display command aliases.
```
# hwi
## Command Function<a name="section445335110416"></a>
## Command Function
This command is used to query information about interrupts.
## Syntax<a name="section1795712553416"></a>
hwi
## Syntax
## Parameters<a name="section92544592410"></a>
None
## Usage<a name="section104151141252"></a>
- Run **hwi** to display the interrupt IDs, count of interrupts, and registered interrupt names of the system.
- If **LOSCFG\_CPUP\_INCLUDE\_IRQ** is enabled, the interrupt handling time \(ATime\), CPU usage, and type of each interrupt are also displayed.
## Example<a name="section11545171957"></a>
Run **hwi**.
## Output<a name="section075617368542"></a>
- Interrupt information \(**LOSCFG\_CPUP\_INCLUDE\_IRQ** disabled\):
```
OHOS # hwi
InterruptNo Count Name
0: 0:
1: 1025641:
2: 0:
29: 824049:
37: 0: rtc_alarm
38: 24: uart_pl011
48: 3: GPIO
59: 0:
62: 530: MMC_IRQ
63: 70: MMC_IRQ
64: 280: ETH
67: 58: tde
68: 0: JPGE_0
69: 0: IVE
70: 0: VGS
72: 0: VEDU_0
73: 0: nnie0
74: 0: nnie_gdc0
75: 0: VPSS
76: 0: VI_PROC0
77: 0: JPEGD_0
83: 49455: HIFB_SOFT_INT
87: 0: AIO interrupt
88: 0: VI_CAP0
89: 0: MIPI_RX
90: 49455: VO int
91: 49456: HIFB Int
96: 17601: MMC_IRQ
100: 0: SPI_HI35XX
101: 0: SPI_HI35XX
102: 0: SPI_HI35XX
```
- Interrupt information \(**LOSCFG\_CPUP\_INCLUDE\_IRQ** enabled\):
```
OHOS # hwi
InterruptNo Count ATime(us) CPUUSE CPUUSE10s CPUUSE1s Mode Name
0: 0 0 0.0 0.0 0.0 normal
1: 937031 0 0.1 0.1 0.1 normal
2: 0 0 0.0 0.0 0.0 normal
29: 726166 5 0.54 0.57 0.59 normal
37: 0 0 0.0 0.0 0.0 normal rtc_alarm
38: 17 5 0.0 0.0 0.0 normal uart_pl011
48: 3 4 0.0 0.0 0.0 normal GPIO
59: 0 0 0.0 0.0 0.0 normal
62: 531 1 0.0 0.0 0.0 normal MMC_IRQ
63: 69 1 0.0 0.0 0.0 normal MMC_IRQ
64: 292 2 0.0 0.0 0.0 normal ETH
67: 54 76 0.0 0.0 0.0 shared tde
68: 0 0 0.0 0.0 0.0 shared JPGE_0
69: 0 0 0.0 0.0 0.0 shared IVE
70: 0 0 0.0 0.0 0.0 shared VGS
72: 0 0 0.0 0.0 0.0 shared VEDU_0
73: 0 0 0.0 0.0 0.0 shared nnie0
74: 0 0 0.0 0.0 0.0 shared nnie_gdc0
75: 0 0 0.0 0.0 0.0 shared VPSS
76: 0 0 0.0 0.0 0.0 shared VI_PROC0
77: 0 0 0.0 0.0 0.0 shared JPEGD_0
83: 45529 8 0.5 0.5 0.5 shared HIFB_SOFT_INT
87: 0 0 0.0 0.0 0.0 shared AIO interrupt
88: 0 0 0.0 0.0 0.0 shared VI_CAP0
89: 0 0 0.0 0.0 0.0 shared MIPI_RX
90: 45534 11 0.6 0.7 0.7 shared VO int
91: 45533 2 0.1 0.1 0.1 shared HIFB Int
96: 17383 2 0.0 0.0 0.0 normal MMC_IRQ
100: 0 0 0.0 0.0 0.0 normal SPI_HI35XX
101: 0 0 0.0 0.0 0.0 normal SPI_HI35XX
102: 0 0 0.0 0.0 0.0 normal SPI_HI35XX
```
**Table 1** Output
<a name="table809mcpsimp"></a>
<table><thead align="left"><tr id="row814mcpsimp"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p816mcpsimp"><a name="p816mcpsimp"></a><a name="p816mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p818mcpsimp"><a name="p818mcpsimp"></a><a name="p818mcpsimp"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row20360171311398"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p172391401402"><a name="p172391401402"></a><a name="p172391401402"></a>InterruptNo</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p42381940174013"><a name="p42381940174013"></a><a name="p42381940174013"></a>Interrupt ID</p>
</td>
</tr>
<tr id="row262535153913"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1823824014402"><a name="p1823824014402"></a><a name="p1823824014402"></a>Count</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p14237040144018"><a name="p14237040144018"></a><a name="p14237040144018"></a>Number of interrupts</p>
</td>
</tr>
<tr id="row9683953153916"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p6236124084018"><a name="p6236124084018"></a><a name="p6236124084018"></a>Name</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18235164014401"><a name="p18235164014401"></a><a name="p18235164014401"></a>Registered interrupt name</p>
</td>
</tr>
<tr id="row85721136402"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1123434017409"><a name="p1123434017409"></a><a name="p1123434017409"></a>ATime</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p2023424094014"><a name="p2023424094014"></a><a name="p2023424094014"></a>Interrupt handling time</p>
</td>
</tr>
<tr id="row19180126151415"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p6233040164020"><a name="p6233040164020"></a><a name="p6233040164020"></a>CPUUSE</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p5232840104015"><a name="p5232840104015"></a><a name="p5232840104015"></a>CPU usage</p>
</td>
</tr>
<tr id="row511517331702"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p14231040164014"><a name="p14231040164014"></a><a name="p14231040164014"></a>CPUUSE10s</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1323011409405"><a name="p1323011409405"></a><a name="p1323011409405"></a>CPU usage within the last 10 seconds</p>
</td>
</tr>
<tr id="row1868124415413"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p9681144414114"><a name="p9681144414114"></a><a name="p9681144414114"></a>CPUUSE1s</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p76814443417"><a name="p76814443417"></a><a name="p76814443417"></a>CPU usage within the last 1 second</p>
</td>
</tr>
<tr id="row7681164454112"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1968124412411"><a name="p1968124412411"></a><a name="p1968124412411"></a>mode</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p268134415419"><a name="p268134415419"></a><a name="p268134415419"></a>Interrupt type, which can be any of the following:</p>
<a name="ul682912412419"></a><a name="ul682912412419"></a><ul id="ul682912412419"><li><strong id="b35357873733839"><a name="b35357873733839"></a><a name="b35357873733839"></a>normal</strong>: non-shared interrupt.</li><li><strong id="b209107492433839"><a name="b209107492433839"></a><a name="b209107492433839"></a>shared</strong>: shared interrupt.</li></ul>
</td>
</tr>
</tbody>
</table>
hwi
## Parameters
None.
## Usage Guidelines
- Run **hwi** to display the interrupt IDs, count of interrupts, and registered interrupt names of the system.
- If **LOSCFG_CPUP_INCLUDE_IRQ** is enabled, the interrupt handling time (ATime), CPU usage, and type of each interrupt are also displayed.
## Example
Run **hwi**.
## Output
- Interrupt information (**LOSCFG_CPUP_INCLUDE_IRQ** disabled):
```
OHOS # hwi
InterruptNo Count Name
0: 0:
1: 1025641:
2: 0:
29: 824049:
37: 0: rtc_alarm
38: 24: uart_pl011
48: 3: GPIO
59: 0:
62: 530: MMC_IRQ
63: 70: MMC_IRQ
64: 280: ETH
67: 58: tde
68: 0: JPGE_0
69: 0: IVE
70: 0: VGS
72: 0: VEDU_0
73: 0: nnie0
74: 0: nnie_gdc0
75: 0: VPSS
76: 0: VI_PROC0
77: 0: JPEGD_0
83: 49455: HIFB_SOFT_INT
87: 0: AIO interrupt
88: 0: VI_CAP0
89: 0: MIPI_RX
90: 49455: VO int
91: 49456: HIFB Int
96: 17601: MMC_IRQ
100: 0: SPI_HI35XX
101: 0: SPI_HI35XX
102: 0: SPI_HI35XX
```
- Interrupt information (**LOSCFG_CPUP_INCLUDE_IRQ** enabled):
```
OHOS # hwi
InterruptNo Count ATime(us) CPUUSE CPUUSE10s CPUUSE1s Mode Name
0: 0 0 0.0 0.0 0.0 normal
1: 937031 0 0.1 0.1 0.1 normal
2: 0 0 0.0 0.0 0.0 normal
29: 726166 5 0.54 0.57 0.59 normal
37: 0 0 0.0 0.0 0.0 normal rtc_alarm
38: 17 5 0.0 0.0 0.0 normal uart_pl011
48: 3 4 0.0 0.0 0.0 normal GPIO
59: 0 0 0.0 0.0 0.0 normal
62: 531 1 0.0 0.0 0.0 normal MMC_IRQ
63: 69 1 0.0 0.0 0.0 normal MMC_IRQ
64: 292 2 0.0 0.0 0.0 normal ETH
67: 54 76 0.0 0.0 0.0 shared tde
68: 0 0 0.0 0.0 0.0 shared JPGE_0
69: 0 0 0.0 0.0 0.0 shared IVE
70: 0 0 0.0 0.0 0.0 shared VGS
72: 0 0 0.0 0.0 0.0 shared VEDU_0
73: 0 0 0.0 0.0 0.0 shared nnie0
74: 0 0 0.0 0.0 0.0 shared nnie_gdc0
75: 0 0 0.0 0.0 0.0 shared VPSS
76: 0 0 0.0 0.0 0.0 shared VI_PROC0
77: 0 0 0.0 0.0 0.0 shared JPEGD_0
83: 45529 8 0.5 0.5 0.5 shared HIFB_SOFT_INT
87: 0 0 0.0 0.0 0.0 shared AIO interrupt
88: 0 0 0.0 0.0 0.0 shared VI_CAP0
89: 0 0 0.0 0.0 0.0 shared MIPI_RX
90: 45534 11 0.6 0.7 0.7 shared VO int
91: 45533 2 0.1 0.1 0.1 shared HIFB Int
96: 17383 2 0.0 0.0 0.0 normal MMC_IRQ
100: 0 0 0.0 0.0 0.0 normal SPI_HI35XX
101: 0 0 0.0 0.0 0.0 normal SPI_HI35XX
102: 0 0 0.0 0.0 0.0 normal SPI_HI35XX
```
**Table 1** Output description
| Parameter| Description|
| -------- | -------- |
| InterruptNo | Interrupt number.|
| Count | Number of interrupts.|
| Name | Registered interrupt name.|
| ATime | Interrupt handling time.|
| CPUUSE | CPU usage.|
| CPUUSE10s | CPU usage in the last 10s.|
| CPUUSE1s | CPU usage in the last 1s.|
| mode | Interrupt type, which can be any of the following:<br>- **normal**: non-shared interrupt.<br>- **shared**: shared interrupt.|
# kill
## Command Function<a name="section366714216619"></a>
This command is used to send a signal to a specified process.
## Syntax<a name="section8833164614615"></a>
kill \[-l \[_signo_\] | _-s signo_ | _-signo_\] _pid..._
## Parameters<a name="section12809111019453"></a>
**Table 1** Parameter description
<a name="table438mcpsimp"></a>
<table><thead align="left"><tr id="row444mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p446mcpsimp"><a name="p446mcpsimp"></a><a name="p446mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="51.92%" id="mcps1.2.4.1.2"><p id="p448mcpsimp"><a name="p448mcpsimp"></a><a name="p448mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27.08%" id="mcps1.2.4.1.3"><p id="p450mcpsimp"><a name="p450mcpsimp"></a><a name="p450mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row6412714183316"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p940219144332"><a name="p940219144332"></a><a name="p940219144332"></a>--help</p>
</td>
<td class="cellrowborder" valign="top" width="51.92%" headers="mcps1.2.4.1.2 "><p id="p3402191493310"><a name="p3402191493310"></a><a name="p3402191493310"></a>Displays the parameters supported by the <strong id="b277973411569"><a name="b277973411569"></a><a name="b277973411569"></a>kill</strong> command.</p>
</td>
<td class="cellrowborder" valign="top" width="27.08%" headers="mcps1.2.4.1.3 "><p id="p4402161493316"><a name="p4402161493316"></a><a name="p4402161493316"></a>N/A</p>
</td>
</tr>
<tr id="row114122143330"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p0402314103315"><a name="p0402314103315"></a><a name="p0402314103315"></a>-l</p>
</td>
<td class="cellrowborder" valign="top" width="51.92%" headers="mcps1.2.4.1.2 "><p id="p640281413313"><a name="p640281413313"></a><a name="p640281413313"></a>Lists the names and numbers of signals.</p>
</td>
<td class="cellrowborder" valign="top" width="27.08%" headers="mcps1.2.4.1.3 "><p id="p19402191416337"><a name="p19402191416337"></a><a name="p19402191416337"></a>N/A</p>
</td>
</tr>
<tr id="row12412131493314"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p1240220141335"><a name="p1240220141335"></a><a name="p1240220141335"></a>-s</p>
</td>
<td class="cellrowborder" valign="top" width="51.92%" headers="mcps1.2.4.1.2 "><p id="p8402131411331"><a name="p8402131411331"></a><a name="p8402131411331"></a>Sends signals</p>
</td>
<td class="cellrowborder" valign="top" width="27.08%" headers="mcps1.2.4.1.3 "><p id="p140211415339"><a name="p140211415339"></a><a name="p140211415339"></a>N/A</p>
</td>
</tr>
<tr id="row1441281443320"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p14402171410332"><a name="p14402171410332"></a><a name="p14402171410332"></a>signo</p>
</td>
<td class="cellrowborder" valign="top" width="51.92%" headers="mcps1.2.4.1.2 "><p id="p114023144336"><a name="p114023144336"></a><a name="p114023144336"></a>Specifies the signal number.</p>
</td>
<td class="cellrowborder" valign="top" width="27.08%" headers="mcps1.2.4.1.3 "><p id="p240212145333"><a name="p240212145333"></a><a name="p240212145333"></a>[1,30]</p>
</td>
</tr>
<tr id="row13411714143310"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p5402131463314"><a name="p5402131463314"></a><a name="p5402131463314"></a>pid</p>
</td>
<td class="cellrowborder" valign="top" width="51.92%" headers="mcps1.2.4.1.2 "><p id="p7402014113310"><a name="p7402014113310"></a><a name="p7402014113310"></a>Specifies the process ID.</p>
</td>
<td class="cellrowborder" valign="top" width="27.08%" headers="mcps1.2.4.1.3 "><p id="p24021514183317"><a name="p24021514183317"></a><a name="p24021514183317"></a>[1,MAX_INT]</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-notice.gif) **NOTICE:**
>The value range of **signo** is \[0, 64\]. The recommended value range is \[1, 30\], and other values in the value range are reserved.
## Usage<a name="section15935131220717"></a>
- The **signo** and **pid** parameters are mandatory.
- The **pid** value range varies depending on the system configuration. For example, if the maximum **pid** value supported by the system is **256**, this value range is \[1-256\].
## Example<a name="section79281818476"></a>
- Query the process list before killing process 42.
```
OHOS:/$ ps
allCpu(%): 4.67 sys, 195.33 idle
PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName
1 -1 1 0 Pending 0x33b000 0xbb000 0x4db02 0.0 init
2 -1 2 0 Pending 0xdabc08 0 0xdabc08 1.14 KProcess
3 1 3 7 Pending 0x72e000 0x1a3000 0x1d24c2 0.0 foundation
4 1 4 8 Pending 0x362000 0xbb000 0x5c6ff 0.0 bundle_daemon
5 1 5 1 Pending 0xdfa000 0x2e7000 0x1484f0 0.0 appspawn
6 1 6 0 Pending 0x688000 0x137000 0x11bca0 0.0 media_server
7 1 7 0 Pending 0x9d2000 0x103000 0xa1cdf 0.88 wms_server
8 1 8 2 Pending 0x1f5000 0x48000 0x47dc2 0.2 mksh
12 1 12 0 Pending 0x4d4000 0x112000 0xe0882 0.0 deviceauth_service
13 1 13 0 Pending 0x34f000 0xbd000 0x51799 0.0 sensor_service
14 1 14 2 Pending 0x34e000 0xb3000 0x52184 0.0 ai_server
15 1 15 0 Pending 0x61f000 0x13b000 0x168071 0.45 softbus_server
42 8 42 2 Pending 0x1c1000 0x3a000 0x1106a 0.9 test_demo
43 8 43 2 Running 0x1d7000 0x3a000 0x1e577 0.0 toybox
```
- Send signal 9 \(the default action of **SIGKILL** is to immediately terminate the process\) to process 42 test\_demo \(a user-mode process\). Then, check the current process list. The commands **kill -s 9 42** and **kill -9 42** have the same effect.
```
OHOS:/$ kill -s 9 42
OHOS:/$
[1] + Killed ./nfs/test_demo
OHOS:/$ ps
allCpu(%): 4.73 sys, 195.27 idle
PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName
1 -1 1 0 Pending 0x33b000 0xbb000 0x4e01c 0.0 init
2 -1 2 0 Pending 0xda5fa4 0 0xda5fa4 1.14 KProcess
3 1 3 7 Pending 0x72e000 0x1a3000 0x1d29dc 0.0 foundation
4 1 4 8 Pending 0x362000 0xbb000 0x5cc19 0.0 bundle_daemon
5 1 5 1 Pending 0xdfa000 0x2e7000 0x148a0a 0.0 appspawn
6 1 6 0 Pending 0x688000 0x137000 0x11c1ba 0.0 media_server
7 1 7 0 Pending 0x9d2000 0x103000 0xa21f9 0.89 wms_server
8 1 8 2 Pending 0x1f5000 0x48000 0x482dc 0.2 mksh
12 1 12 0 Pending 0x4d4000 0x112000 0xe0d9c 0.0 deviceauth_service
13 1 13 0 Pending 0x34f000 0xbd000 0x51cb3 0.0 sensor_service
14 1 14 2 Pending 0x34e000 0xb3000 0x5269e 0.0 ai_server
15 1 15 0 Pending 0x61f000 0x13b000 0x16858b 0.51 softbus_server
45 8 45 2 Running 0x1d7000 0x3a000 0x1e9f5 0.0 toybox
```
- Run the **kill -100 31** command.
## Output<a name="section12742311179"></a>
**Example 1**: The signal is successfully sent to process 42.
## Command Function
This command is used to send a signal to a process to terminate the abnormal application.
## Syntax
kill [-l [_signo_] | _-s signo_ | _-signo_] *pid...*
## Parameters
**Table 1** Parameter description
| Parameter | Description | Value Range |
| ------ | -------------------------- | ----------- |
| --help | Displays the parameters supported by the **kill** command.| N/A |
| -l | Lists the names and numbers of signals. | N/A |
| -s | Sends a signal. | N/A |
| signo | Specifies the signal number. | [1, 30] |
| pid | Specifies the process ID. | [1, MAX_INT] |
> **NOTICE**<br>
> The value range of **signo** is [0, 64]. The recommended value range is [1, 30], and other values in the value range are reserved.
## Usage Guidelines
- The **signo** and **pid** parameters are mandatory.
- The **pid** value range varies depending on the system configuration. For example, if the maximum **pid** value supported by the system is **256**, this value range is [1, 256].
## Note
The **kill** command is not supported by the shell. mksh supports it. To switch to mksh, run **cd bin;** and **./mksh**.
## Example
- Query the process list before killing process 42.
```
OHOS:/$ ps
allCpu(%): 4.67 sys, 195.33 idle
PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName
1 -1 1 0 Pending 0x33b000 0xbb000 0x4db02 0.0 init
2 -1 2 0 Pending 0xdabc08 0 0xdabc08 1.14 KProcess
3 1 3 7 Pending 0x72e000 0x1a3000 0x1d24c2 0.0 foundation
4 1 4 8 Pending 0x362000 0xbb000 0x5c6ff 0.0 bundle_daemon
5 1 5 1 Pending 0xdfa000 0x2e7000 0x1484f0 0.0 appspawn
6 1 6 0 Pending 0x688000 0x137000 0x11bca0 0.0 media_server
7 1 7 0 Pending 0x9d2000 0x103000 0xa1cdf 0.88 wms_server
8 1 8 2 Pending 0x1f5000 0x48000 0x47dc2 0.2 mksh
10 5 5 101 Pending 0x11ec000 0x2f9000 0x206047 0.93 com.example.launcher
12 1 12 0 Pending 0x4d4000 0x112000 0xe0882 0.0 deviceauth_service
13 1 13 0 Pending 0x34f000 0xbd000 0x51799 0.0 sensor_service
14 1 14 2 Pending 0x34e000 0xb3000 0x52184 0.0 ai_server
15 1 15 0 Pending 0x61f000 0x13b000 0x168071 0.45 softbus_server
42 8 42 2 Pending 0x1c1000 0x3a000 0x1106a 0.9 test_demo
43 8 43 2 Running 0x1d7000 0x3a000 0x1e577 0.0 toybox
```
- Send signal 9 (the default action of **SIGKILL** is to immediately terminate the process) to process 42 test_demo (a user-mode process). Then, check the current process list. The commands **kill -s 9 42** and **kill -9 42** have the same effect.
```
OHOS:/$ kill -s 9 42
OHOS:/$
[1] + Killed ./nfs/test_demo
OHOS:/$ ps
allCpu(%): 4.73 sys, 195.27 idle
PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName
1 -1 1 0 Pending 0x33b000 0xbb000 0x4e01c 0.0 init
2 -1 2 0 Pending 0xda5fa4 0 0xda5fa4 1.14 KProcess
3 1 3 7 Pending 0x72e000 0x1a3000 0x1d29dc 0.0 foundation
4 1 4 8 Pending 0x362000 0xbb000 0x5cc19 0.0 bundle_daemon
5 1 5 1 Pending 0xdfa000 0x2e7000 0x148a0a 0.0 appspawn
6 1 6 0 Pending 0x688000 0x137000 0x11c1ba 0.0 media_server
7 1 7 0 Pending 0x9d2000 0x103000 0xa21f9 0.89 wms_server
8 1 8 2 Pending 0x1f5000 0x48000 0x482dc 0.2 mksh
10 5 5 101 Pending 0x11ec000 0x2f9000 0x206561 0.93 com.example.launcher
12 1 12 0 Pending 0x4d4000 0x112000 0xe0d9c 0.0 deviceauth_service
13 1 13 0 Pending 0x34f000 0xbd000 0x51cb3 0.0 sensor_service
14 1 14 2 Pending 0x34e000 0xb3000 0x5269e 0.0 ai_server
15 1 15 0 Pending 0x61f000 0x13b000 0x16858b 0.51 softbus_server
45 8 45 2 Running 0x1d7000 0x3a000 0x1e9f5 0.0 toybox
```
- Run the **kill -100 31** command.
## Output
The command output is as follows:
Example 1: The signal is successfully sent to process 42.
```
OHOS:/$ kill -s 9 42
......@@ -131,10 +107,10 @@ Process 42 is killed.
**Example 2**: The signal fails to be sent to process 31.
```
OHOS:/$ kill -100 31
kill: Unknown signal '(null)'
```
**Unknown signal '\(null\)'** is displayed because the **signo** value **100** exceeds the value range \[0, 64\].
**Unknown signal '(null)'** is displayed because the **signo** value **100** exceeds the value range [0, 64].
# log
## Command Function<a name="section128219131856"></a>
## Command Function
This command is used to set and query log configuration.
## Syntax<a name="section3894181710519"></a>
log level \[_levelNum_\]
## Syntax
log level [_levelNum_]
## Parameters<a name="section7693122310515"></a>
## Parameters
**Table 1** Parameter description
**Table 1** Parameter description
<a name="table237mcpsimp"></a>
<table><thead align="left"><tr id="row243mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p245mcpsimp"><a name="p245mcpsimp"></a><a name="p245mcpsimp"></a><strong id="b3369319192013"><a name="b3369319192013"></a><a name="b3369319192013"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p247mcpsimp"><a name="p247mcpsimp"></a><a name="p247mcpsimp"></a><strong id="b12646112413211"><a name="b12646112413211"></a><a name="b12646112413211"></a>Description</strong></p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p249mcpsimp"><a name="p249mcpsimp"></a><a name="p249mcpsimp"></a><strong id="b13881153318285"><a name="b13881153318285"></a><a name="b13881153318285"></a>Value Range</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row250mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p252mcpsimp"><a name="p252mcpsimp"></a><a name="p252mcpsimp"></a>levelNum</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p254mcpsimp"><a name="p254mcpsimp"></a><a name="p254mcpsimp"></a>Specifies the level of logs to print.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p2270121719813"><a name="p2270121719813"></a><a name="p2270121719813"></a>[0,5]</p>
</td>
</tr>
</tbody>
</table>
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| levelNum | Specifies the level of logs to print.| [0, 5] |
## Usage<a name="section1982111281512"></a>
- This command depends on **LOSCFG\_SHELL\_LK**. Before using this command, select **Enable Shell lk** on **menuconfig**.
## Usage Guidelines
**Debug** ---\> **Enable a Debug Version** ---\> **Enable Shell** ---\> **Enable Shell lK**
- This command can be used only after **LOSCFG_SHELL_LK** is enabled. Before using this command, set **Enable Shell lk** to **Yes** on **menuconfig**.
**Debug** ---&gt; **Enable a Debug Version** ---&gt; **Enable Shell** ---&gt; **Enable Shell lK**
- The **log level** command is used to set the log level, which can be any of the following:
- The **log level** command sets the log level, which can be any of the following:
TRACE_EMG = 0,
TRACE\_EMG = 0,
TRACE_COMMON = 1,
TRACE\_COMMON = 1,
TRACE_ERROR = 2,
TRACE\_ERROR = 2,
TRACE_WARN = 3,
TRACE\_WARN = 3,
TRACE_INFO = 4,
TRACE\_INFO = 4,
TRACE_DEBUG = 5
TRACE\_DEBUG = 5
If the log level specified is not within the value range, a message will be displayed.
If the log level specified is not within the value range, a message will be displayed.
- If **[levelNum]** is not specified, this command displays the current log level and how to use it.
- If **\[levelNum\]** is not specified, this command queries the current log level. The usage method is also displayed.
- If the log level is set to **4** or **5** in the source code of the open-source small system, a large number of logs will be printed.
- If the log level is set to **4** or **5** in the source code of an OpenHarmony small system, a large number of logs will be printed.
## Example<a name="section176301333259"></a>
Run **log level 3**.
## Example
## Output<a name="section14354765415"></a>
Run **log level 3**.
## Output
The log print level is set to WARN.
Setting the log print level to WARN:
```
OHOS # log level 3
Set current log level WARN
```
# memcheck
## Command Function<a name="section191633812516"></a>
## Command Function
This command is used to check whether the dynamically allocated memory block is complete and whether nodes in the memory pool are damaged due to out-of-bounds memory access.
## Syntax<a name="section428816435510"></a>
## Syntax
memcheck
## Parameters<a name="section1939943304411"></a>
None
## Parameters
None.
## Usage Guidelines
## Usage<a name="section228914491951"></a>
- If all nodes in the memory pool are complete, "system memcheck over, all passed!" is displayed.
- If all nodes in the memory pool are complete, "system memcheck over, all passed!" is displayed.
- If a node in the memory pool is incomplete, information about the memory block of the corrupted node is displayed.
- If a node in the memory pool is incomplete, information about the memory block of the corrupted node is displayed.
## Example<a name="section17373205314515"></a>
Run **memcheck**.
## Example
## Output<a name="section13406205385413"></a>
Run **memcheck**.
Example 1: All nodes in the memory pool are complete.
Run **memcheck**, and memory overwriting occurs.
## Output
Example 1: No error is detected.
```
OHOS # memcheck
system memcheck over, all passed!
```
Example 2: Out-of-bounds memory access is detected.
Example 2: Memory overwriting is detected.
```
[L0S DLnkCheckMenl 349, memory check
......@@ -43,7 +52,7 @@ puмExcBuffAddr pc = 0x803ad7a4
puwExcBuffAddr lr = 0x803ad7a4
puwExcBuffAddr sp = 0х80cb7de0
puwExcBuffAddr fp = 0x80cb7dec
*******backtrace begin*******
***backtrace begin***
traceback 0 -- lr = 0х8037cb84
traceback 0 -- fp = 0х80cb7e1c
traceback 1 -- lr = 0х8037033c
......@@ -55,4 +64,3 @@ traceback 3 -- fp = 0х80cb7ea4
traceback 4 -- lr = 0x803ad9e8
traceback 4 -- fp = 9x11111111
```
# oom
## Command Function<a name="section366714216619"></a>
## Command Function
This command is used to query and set the low memory threshold and the PageCache reclaim threshold.
## Syntax<a name="section8833164614615"></a>
## Syntax
oom
oom -i \[_interval_\]
oom -i [_interval_]
oom -m \[_mem byte_\]
oom -m [_mem byte_]
oom -r \[_mem byte_\]
oom -r [_mem byte_]
oom -h | --help
## Parameters<a name="section12809111019453"></a>
**Table 1** Parameter description
<a name="table438mcpsimp"></a>
<table><thead align="left"><tr id="row444mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p446mcpsimp"><a name="p446mcpsimp"></a><a name="p446mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p448mcpsimp"><a name="p448mcpsimp"></a><a name="p448mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p450mcpsimp"><a name="p450mcpsimp"></a><a name="p450mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row451mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p5196112612119"><a name="p5196112612119"></a><a name="p5196112612119"></a>-i [interval]</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p1149945111817"><a name="p1149945111817"></a><a name="p1149945111817"></a>Sets the interval (in ms) for checking the Out Of Memory (OOM) thread task.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p749810571812"><a name="p749810571812"></a><a name="p749810571812"></a>100 to 10000</p>
</td>
</tr>
<tr id="row18583553793"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p95841853292"><a name="p95841853292"></a><a name="p95841853292"></a>-m [mem byte]</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p2058485315912"><a name="p2058485315912"></a><a name="p2058485315912"></a>Sets the low memory threshold (in MB).</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p1584105318917"><a name="p1584105318917"></a><a name="p1584105318917"></a>0 (disables the low memory check) to 1</p>
</td>
</tr>
<tr id="row17926124131218"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p49266245128"><a name="p49266245128"></a><a name="p49266245128"></a>-r [mem byte]</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p159263241121"><a name="p159263241121"></a><a name="p159263241121"></a>Sets the PageCache reclaim threshold.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p692642412121"><a name="p692642412121"></a><a name="p692642412121"></a>Ranging from the low memory threshold to the maximum available system memory</p>
</td>
</tr>
<tr id="row1176110379557"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p4762113745519"><a name="p4762113745519"></a><a name="p4762113745519"></a>-h | --help</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p9762113775517"><a name="p9762113775517"></a><a name="p9762113775517"></a>Displays help information.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p7762133765511"><a name="p7762133765511"></a><a name="p7762133765511"></a>N/A</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section15935131220717"></a>
If no parameter is specified, this command displays the current OOM configuration.
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>If the system memory is insufficient, the system displays a message indicating the insufficiency.
## Example<a name="section387104374416"></a>
## Parameters
**Table 1** Parameter description
| Parameter | Description | Value Range |
| ----------------------- | ------------------------------- | ------------------------------------------------------------ |
| -i [interval] | Sets the interval (in ms) for checking the Out Of Memory (OOM) thread task.| [100, 10000] |
| -m [mem byte] | Sets the low memory threshold (in MB). | 0 to 1<br>The value **0** means not to perform the low memory threshold check. |
| -r [mem byte] | Sets the PageCache reclaim threshold. | Low memory threshold to the maximum available memory of the system<br>Generally, the size of a PageCache is 4 KB. Sometimes, it is 16 KB to 64 KB. |
| -h \| --help | Displays help information. | N/A |
## Usage Guidelines
If no parameter is specified, this command displays the current OOM configuration.
> **NOTE**<br>
> If the system memory is insufficient, the system displays a message indicating the insufficiency.
## Example
Run the following commands:
- oom
- oom -i 100
- oom
- oom -i 100
## Output<a name="section12742311179"></a>
## Output
Example 1: The OOM configuration is displayed by default.
Example 1: displaying OOM configuration
```
OHOS:/$ oom
......@@ -88,6 +62,7 @@ OHOS:/$ oom
Information displayed when the system memory is insufficient:
```
T:20 Enter:IT MEM 00M 001
[oom] OS is in low memory state
......@@ -124,7 +99,7 @@ R10 = 0xa0a0a0a
R11 = 0x20e20c8c
R12 = 0х0
CPSR = 0х80000010
*******backtrace beain*******
***backtrace beain***
traceback 0 -- lr = 0x9242e1c fp = 0х20e20cc4 lr in /usr/bin/testsuits apr 0x4be1c
traceback 1 -- 1r = 0х92430cc fp = 0x20e20cdc lr in /usr/bin/testsuits app --> 0x4c0cc
traceback 2 -- 1r = 0x9396ab0 fp = 0x20e20cec lr in /usr/bin/testsuits app -> 0х19fab0
......@@ -133,49 +108,23 @@ traceback 4 -- lr = 0x92427d4 fp = 0x20e20d44 lr in /usr/bin/testsuits app --> 0
traceback 5 -- 1r = 0x20c4df50 fp = 0хb0b0b0b 1r in /1ib/libc.so - -> 0x62f50
```
Example 2: setting the OOM check interval to 100 ms
Example 2: The OOM check interval is set to 100 ms.
```
OHOS:/$ oom -i 100
[oom] set oom check interval (100)ms successful
```
**Table 2** Output
<a name="table487mcpsimp"></a>
<table><thead align="left"><tr id="row492mcpsimp"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p494mcpsimp"><a name="p494mcpsimp"></a><a name="p494mcpsimp"></a>Output</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p496mcpsimp"><a name="p496mcpsimp"></a><a name="p496mcpsimp"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row502mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p583513382179"><a name="p583513382179"></a><a name="p583513382179"></a>[oom] OS is in low memory state</p>
<p id="p636114453553"><a name="p636114453553"></a><a name="p636114453553"></a>total physical memory: 0x1bcf000(byte), used: 0x1b50000(byte), free: 0x7f000(byte), low memory threshold: 0x80000(byte)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p19833143819174"><a name="p19833143819174"></a><a name="p19833143819174"></a>The operating system has low memory.</p>
<p id="p83883291587"><a name="p83883291587"></a><a name="p83883291587"></a>The available physical memory in the operating system is <strong id="b15343050123397"><a name="b15343050123397"></a><a name="b15343050123397"></a>0x1bcf000</strong> bytes, <strong id="b18697901323397"><a name="b18697901323397"></a><a name="b18697901323397"></a>0x1b50000</strong> bytes have been used, and <strong id="b3252944373397"><a name="b3252944373397"></a><a name="b3252944373397"></a>0x7f000</strong> bytes are available. The current low memory threshold is <strong id="b13811086363397"><a name="b13811086363397"></a><a name="b13811086363397"></a>0x80000</strong> bytes.</p>
</td>
</tr>
<tr id="row1990234224612"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p3902144294612"><a name="p3902144294612"></a><a name="p3902144294612"></a>[oom] candidate victim process init pid: 1, actual phy mem byte: 82602</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p13903144284610"><a name="p13903144284610"></a><a name="p13903144284610"></a>Memory usage of each process. The physical memory occupied by the <strong id="b143686319910"><a name="b143686319910"></a><a name="b143686319910"></a>init</strong> process is 82602 bytes.</p>
</td>
</tr>
<tr id="row520212272335"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p172038278339"><a name="p172038278339"></a><a name="p172038278339"></a>[oom] candidate victim process UserProcess12 pid: 12, actual phy mem byte: 25951558</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p112034276331"><a name="p112034276331"></a><a name="p112034276331"></a>The actual memory used by the <strong id="b16405477923397"><a name="b16405477923397"></a><a name="b16405477923397"></a>UserProcess12</strong> process is <strong id="b10952024983397"><a name="b10952024983397"></a><a name="b10952024983397"></a>25951558</strong> bytes.</p>
</td>
</tr>
<tr id="row3273195033416"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p184989213512"><a name="p184989213512"></a><a name="p184989213512"></a>[oom] max phy mem used process UserProcess12 pid: 12, actual phy mem: 25951558</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p112741750143417"><a name="p112741750143417"></a><a name="p112741750143417"></a>The process that uses the most memory currently is <strong id="b17770979863397"><a name="b17770979863397"></a><a name="b17770979863397"></a>UserProcess12</strong>.</p>
</td>
</tr>
<tr id="row16442089365"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p045148153618"><a name="p045148153618"></a><a name="p045148153618"></a>excFrom: User!</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p6452818367"><a name="p6452818367"></a><a name="p6452818367"></a>The system memory is low, and the <strong id="b4088490143397"><a name="b4088490143397"></a><a name="b4088490143397"></a>UserProcess12</strong> process fails to apply for memory and exits.</p>
</td>
</tr>
</tbody>
</table>
**Table 2** Output description
| Parameter | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [oom] OS is in low memory state<br>total physical memory: 0x1bcf000(byte), used: 0x1b50000(byte), free: 0x7f000(byte), low memory threshold: 0x80000(byte) | The OS has low memory.<br>The total physical memory is **0x1bcf000** bytes, **0x1b50000** bytes are used, and **0x7f000** bytes are left.<br/>The current lower memory threshold is **0x80000** bytes. |
| [oom] candidate victim process init pid: 1, actual phy mem byte: 82602 | The memory occupied by the **init** process is 82602 bytes. |
| [oom] candidate victim process UserProcess12 pid: 12, actual phy mem byte: 25951558 | The memory used by the **UserProcess12** process is **25951558** bytes. |
| [oom] max phy mem used process UserProcess12 pid: 12, actual phy mem: 25951558 | The process that uses the most memory currently is **UserProcess12**. |
| excFrom: User! | The system memory is low, and the **UserProcess12** process fails to apply for memory and exits. |
# pmm
## Command Function<a name="section445335110416"></a>
## Command Function
This command is used to check the usage of the physical pages of the system memory and the page cache.
## Syntax<a name="section1795712553416"></a>
## Syntax
pmm
## Parameters<a name="section92544592410"></a>
None
## Parameters
None.
## Usage Guidelines
This command is available only in the **Debug** version.
## Usage<a name="section104151141252"></a>
This command is available only in the **Debug** version.
## Example
## Example<a name="section11545171957"></a>
Run **pmm**.
Run **pmm**.
## Output<a name="section075617368542"></a>
## Output
Usage of physical pages:
......@@ -49,62 +55,17 @@ Vnode number = 67
Vnode memory size = 10720(B)
```
**Table 1** Output
<a name="table5579102611579"></a>
<table><thead align="left"><tr id="row12579162613572"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p18579122619578"><a name="p18579122619578"></a><a name="p18579122619578"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p11579182635718"><a name="p11579182635718"></a><a name="p11579182635718"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1457942675720"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p2058042605713"><a name="p2058042605713"></a><a name="p2058042605713"></a>phys_seg</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1058062614579"><a name="p1058062614579"></a><a name="p1058062614579"></a>Address of the physical page control block</p>
</td>
</tr>
<tr id="row14580192616575"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p858062615712"><a name="p858062615712"></a><a name="p858062615712"></a>base</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1858082617577"><a name="p1858082617577"></a><a name="p1858082617577"></a>First physical page address, that is, start address of the physical page memory</p>
</td>
</tr>
<tr id="row17580826115719"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p5580226155713"><a name="p5580226155713"></a><a name="p5580226155713"></a>size</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p85808262572"><a name="p85808262572"></a><a name="p85808262572"></a>Size of the physical page memory</p>
</td>
</tr>
<tr id="row161931831175912"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p201931631185913"><a name="p201931631185913"></a><a name="p201931631185913"></a>free_pages</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1919383125911"><a name="p1919383125911"></a><a name="p1919383125911"></a>Number of free physical pages</p>
</td>
</tr>
<tr id="row1397105119596"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p0397951175918"><a name="p0397951175918"></a><a name="p0397951175918"></a>active anon</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1139715117599"><a name="p1139715117599"></a><a name="p1139715117599"></a>Number of active anonymous pages in the page cache</p>
</td>
</tr>
<tr id="row16409173520010"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p941012351409"><a name="p941012351409"></a><a name="p941012351409"></a>inactive anon</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1341012355019"><a name="p1341012355019"></a><a name="p1341012355019"></a>Number of inactive anonymous pages in the page cache</p>
</td>
</tr>
<tr id="row467016386014"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p10670103818015"><a name="p10670103818015"></a><a name="p10670103818015"></a>active file</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1267012382019"><a name="p1267012382019"></a><a name="p1267012382019"></a>Number of active file pages in the page cache</p>
</td>
</tr>
<tr id="row18966641507"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p5966741706"><a name="p5966741706"></a><a name="p5966741706"></a>inactive file</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p17966174115018"><a name="p17966174115018"></a><a name="p17966174115018"></a>Number of inactive file pages in the page cache</p>
</td>
</tr>
<tr id="row13183445101"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p318394514018"><a name="p318394514018"></a><a name="p318394514018"></a>pmm pages</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1616375952018"><a name="p1616375952018"></a><a name="p1616375952018"></a><strong id="b161631659162014"><a name="b161631659162014"></a><a name="b161631659162014"></a>total</strong>: total number of physical pages.</p>
<p id="p2029802122113"><a name="p2029802122113"></a><a name="p2029802122113"></a><strong id="b429822122113"><a name="b429822122113"></a><a name="b429822122113"></a>used</strong>: number of used physical pages.</p>
<p id="p1218312452014"><a name="p1218312452014"></a><a name="p1218312452014"></a><strong id="b132798755433826"><a name="b132798755433826"></a><a name="b132798755433826"></a>free</strong>: number of free physical pages.</p>
</td>
</tr>
</tbody>
</table>
**Table 1** Output description
| Parameter| Description|
| -------- | -------- |
| phys_seg | Address of the physical page control block.|
| base | First physical page address, that is, start address of the physical page memory.|
| size | Size of the physical page memory.|
| free_pages | Number of free physical pages.|
| active&nbsp;anon | Number of active anonymous pages in the page cache.|
| inactive&nbsp;anon | Number of inactive anonymous pages in the page cache.|
| active&nbsp;file | Number of active file pages in the page cache.|
| inactive&nbsp;file | Number of inactive file pages in the page cache.|
| pmm&nbsp;pages | **total** indicates the total number of physical pages. <br/>**used** indicates the number of used physical pages. <br/>**free** indicates the number of idle physical pages. |
# reboot
## Command Function<a name="section20643141481314"></a>
## Command Function
This command is used to restart a device.
## Syntax<a name="section1075441721316"></a>
## Syntax
reboot
## Parameters<a name="section1472810220135"></a>
None
## Parameters
None.
## Usage Guidelines
## Usage<a name="section186772414131"></a>
After the **reboot** command is executed, the device restarts immediately.
After the **reboot** command is executed, the device restarts immediately.
## Example<a name="section4764192791314"></a>
## Example
reboot
## Output<a name="section5791253155517"></a>
None
## Output
None.
# reset
## Command Function<a name="section366714216619"></a>
## Command Function
This command is used to restart a device.
## Syntax<a name="section8833164614615"></a>
## Syntax
reset
## Parameters<a name="section12809111019453"></a>
None
## Parameters
None.
## Usage Guidelines
## Usage<a name="section15935131220717"></a>
After the **reset** command is executed, the device restarts immediately.
After the **reset** command is executed, the device restarts immediately.
## Example<a name="section79281818476"></a>
## Example
Run **reset**.
Run **reset**.
## Output<a name="section12742311179"></a>
None
## Output
None.
# sem
## Command Function<a name="section366714216619"></a>
## Command Function
This command is used to query information about kernel semaphores.
## Syntax<a name="section8833164614615"></a>
sem \[_ID__ / fulldata_\]
## Syntax
sem [_ID__ / fulldata_]
## Parameters
**Table 1** Parameter description
## Parameters<a name="section12809111019453"></a>
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| ID | Specifies the semaphore ID.| [0, 1023] or [0x0, 0x3FF]|
| fulldata | Displays information about all semaphores in use. <br/>The displayed information includes **SemID**, **Count**, **Original Count**, **Creator TaskEntry**, and **Last Access Time**. | N/A |
**Table 1** Parameter description
<a name="table438mcpsimp"></a>
<table><thead align="left"><tr id="row444mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p446mcpsimp"><a name="p446mcpsimp"></a><a name="p446mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p448mcpsimp"><a name="p448mcpsimp"></a><a name="p448mcpsimp"></a>Parameters</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p450mcpsimp"><a name="p450mcpsimp"></a><a name="p450mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row451mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p453mcpsimp"><a name="p453mcpsimp"></a><a name="p453mcpsimp"></a>ID</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p455mcpsimp"><a name="p455mcpsimp"></a><a name="p455mcpsimp"></a>Specifies the semaphore ID.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p14422125918562"><a name="p14422125918562"></a><a name="p14422125918562"></a>[0, 1023] or [0x0, 0x3FF]</p>
</td>
</tr>
<tr id="row458mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p460mcpsimp"><a name="p460mcpsimp"></a><a name="p460mcpsimp"></a>fulldata</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p462mcpsimp"><a name="p462mcpsimp"></a><a name="p462mcpsimp"></a>Queries information about all the semaphores in use. The information includes <strong id="b189454249533849"><a name="b189454249533849"></a><a name="b189454249533849"></a>SemID</strong>, <strong id="b162724654333849"><a name="b162724654333849"></a><a name="b162724654333849"></a>Count</strong>, <strong id="b111325307233849"><a name="b111325307233849"></a><a name="b111325307233849"></a>OriginalCount</strong>, <strong id="b182850346833849"><a name="b182850346833849"></a><a name="b182850346833849"></a>Creator(TaskEntry)</strong>, and <strong id="b213750533633849"><a name="b213750533633849"></a><a name="b213750533633849"></a>LastAccessTime</strong>.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="entry464mcpsimpp0"><a name="entry464mcpsimpp0"></a><a name="entry464mcpsimpp0"></a>N/A</p>
</td>
</tr>
</tbody>
</table>
## Usage Guidelines
## Usage<a name="section15935131220717"></a>
- If no parameter is specified, this command displays the semaphore IDs and the number of times that each semaphore is used.
- If no parameter is specified, this command displays the semaphore IDs and the number of times that each semaphore is used.
- If **ID** is specified, the use of the specified semaphore is displayed.
- The **fulldata** parameter depends on **LOSCFG\_DEBUG\_SEMAPHORE**. Before using this parameter, select **Enable Semaphore Debugging** on **menuconfig**.
- If **ID** is specified, the use of the specified semaphore is displayed.
Debug ---\> Enable a Debug Version ---\> Enable Debug LiteOS Kernel Resource ---\> Enable Semaphore Debugging
- The **fulldata** parameter depends on **LOSCFG_DEBUG_SEMAPHORE**. Before using this parameter, set **Enable Semaphore Debugging** to **Yes** on **menuconfig**.
**Debug** ---&gt; **Enable a Debug Version** ---&gt; **Enable Debug LiteOS Kernel Resource** ---&gt; E**nable Semaphore Debugging**
## Example<a name="section79281818476"></a>
## Example
- Run **sem**.
- Configure **LOSCFG\_DEBUG\_SEMAPHORE** and run **sem fulldata**.
- Run **sem**.
## Output<a name="section1975118519456"></a>
- Configure **LOSCFG_DEBUG_SEMAPHORE** and run **sem fulldata**.
## Output
Example 1: brief semaphore information
......@@ -81,31 +67,17 @@ OHOS # sem
0x00000006 0
```
**Table 2** Output
<a name="table487mcpsimp"></a>
<table><thead align="left"><tr id="row492mcpsimp"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p494mcpsimp"><a name="p494mcpsimp"></a><a name="p494mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p496mcpsimp"><a name="p496mcpsimp"></a><a name="p496mcpsimp"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row497mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p499mcpsimp"><a name="p499mcpsimp"></a><a name="p499mcpsimp"></a>SemID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p501mcpsimp"><a name="p501mcpsimp"></a><a name="p501mcpsimp"></a>Semaphore ID</p>
</td>
</tr>
<tr id="row502mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p504mcpsimp"><a name="p504mcpsimp"></a><a name="p504mcpsimp"></a>Count</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p506mcpsimp"><a name="p506mcpsimp"></a><a name="p506mcpsimp"></a>Number of times that the semaphore is used</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE**
>The **ID** value can be in decimal or hexadecimal format.
>When **ID** is a value within \[0, 1023\], semaphore information of the specified ID is displayed. If the specified semaphore is not used, a message is displayed to inform you of this case. For other values, a message is displayed indicating that the parameter is incorrect.
**Table 2** Output description
| Parameter| Description|
| -------- | -------- |
| SemID | Semaphore ID.|
| Count | Number of times that the semaphore is used.|
> **NOTE**<br>
> The **ID** value can be in decimal or hexadecimal format.
>
> When **ID** is a value within [0, 1023], semaphore information of the specified ID is displayed. If the specified semaphore is not used, a message is displayed to inform you of this case. For other values, a message is displayed indicating that the parameter is incorrect.
Example 2: detailed semaphore information
......@@ -141,40 +113,12 @@ Used Semaphore List:
0x38 0x1 0x1 0x404978fc 0x395
```
**Table 3** Output description
<a name="table57783201041"></a>
<table><thead align="left"><tr id="row12778320943"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p153641444643"><a name="p153641444643"></a><a name="p153641444643"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p236413447414"><a name="p236413447414"></a><a name="p236413447414"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row14834640646"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p7829840647"><a name="p7829840647"></a><a name="p7829840647"></a>SemID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p118291440244"><a name="p118291440244"></a><a name="p118291440244"></a>Semaphore ID</p>
</td>
</tr>
<tr id="row78346401141"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p08292401349"><a name="p08292401349"></a><a name="p08292401349"></a>Count</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1829104012416"><a name="p1829104012416"></a><a name="p1829104012416"></a>Number of times that the semaphore is used</p>
</td>
</tr>
<tr id="row1883414404411"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p88291640847"><a name="p88291640847"></a><a name="p88291640847"></a>OriginalCount</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p282916401148"><a name="p282916401148"></a><a name="p282916401148"></a>Original count of the semaphore</p>
</td>
</tr>
<tr id="row148347401646"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1782914401646"><a name="p1782914401646"></a><a name="p1782914401646"></a>Creator</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p168298407419"><a name="p168298407419"></a><a name="p168298407419"></a>Address of the entry function of the thread used to create the semaphore</p>
</td>
</tr>
<tr id="row783415401340"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p18829640549"><a name="p18829640549"></a><a name="p18829640549"></a>LastAccessTime</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p198292406412"><a name="p198292406412"></a><a name="p198292406412"></a>Last time when the semaphore was accessed</p>
</td>
</tr>
</tbody>
</table>
**Table 3** Output description
| Parameter| Description|
| -------- | -------- |
| SemID | Semaphore ID.|
| Count | Number of times that the semaphore is used.|
| OriginalCount | Original count of the semaphore.|
| Creator | Address of the entry function of the thread used to create the semaphore.|
| LastAccessTime | Last time when the semaphore was accessed.|
# stack
## Command Function<a name="section445335110416"></a>
## Command Function
This command is used to check the usage of each stack in the system.
## Syntax<a name="section1795712553416"></a>
## Syntax
stack
## Parameters<a name="section92544592410"></a>
None
## Parameters
None.
## Usage Guidelines
None.
## Usage<a name="section104151141252"></a>
None
## Example
## Example<a name="section11545171957"></a>
Run **stack**.
Run **stack**.
## Output<a name="section075617368542"></a>
## Output
System stack usage:
......@@ -35,40 +40,12 @@ OHOS # stack
exc_stack 0 0x405c9000 0x1000 0x0
```
**Table 1** Output
<a name="table633mcpsimp"></a>
<table><thead align="left"><tr id="row638mcpsimp"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p640mcpsimp"><a name="p640mcpsimp"></a><a name="p640mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p642mcpsimp"><a name="p642mcpsimp"></a><a name="p642mcpsimp"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row643mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p645mcpsimp"><a name="p645mcpsimp"></a><a name="p645mcpsimp"></a>stack name</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p647mcpsimp"><a name="p647mcpsimp"></a><a name="p647mcpsimp"></a>Name of the stack</p>
</td>
</tr>
<tr id="row648mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p650mcpsimp"><a name="p650mcpsimp"></a><a name="p650mcpsimp"></a>cpu id</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p652mcpsimp"><a name="p652mcpsimp"></a><a name="p652mcpsimp"></a>CPU ID</p>
</td>
</tr>
<tr id="row653mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p655mcpsimp"><a name="p655mcpsimp"></a><a name="p655mcpsimp"></a>stack addr</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p657mcpsimp"><a name="p657mcpsimp"></a><a name="p657mcpsimp"></a>Stack address</p>
</td>
</tr>
<tr id="row658mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p660mcpsimp"><a name="p660mcpsimp"></a><a name="p660mcpsimp"></a>total size</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p662mcpsimp"><a name="p662mcpsimp"></a><a name="p662mcpsimp"></a>Total stack size</p>
</td>
</tr>
<tr id="row10101624938"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p610724734"><a name="p610724734"></a><a name="p610724734"></a>used size</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1510024539"><a name="p1510024539"></a><a name="p1510024539"></a>Size of the stack used</p>
</td>
</tr>
</tbody>
</table>
**Table 1** Output description
| Parameter| Description|
| -------- | -------- |
| stack&nbsp;name | Name of the stack.|
| cpu&nbsp;id | CPU number.|
| stack&nbsp;addr | Stack address.|
| total&nbsp;size | Total stack size.|
| used&nbsp;size | Size of the stack used.|
# su
## Command Function<a name="section297810431676"></a>
## Command Function
This command is used to switch the user account.
## Syntax<a name="section157131147876"></a>
su \[_uid_\] \[_gid_\]
## Syntax
su [_uid_] [_gid_]
## Parameters
**Table 1** Parameter description
## Parameters<a name="section04145521671"></a>
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| uid | Specifies the ID of the target user.| - Left blank<br>- [0, 60000] |
| gid | Specifies the ID of the target user group.| - Left blank<br>- [0, 60000] |
**Table 1** Parameter description
<a name="table1049mcpsimp"></a>
<table><thead align="left"><tr id="row1055mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p1057mcpsimp"><a name="p1057mcpsimp"></a><a name="p1057mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="51.93%" id="mcps1.2.4.1.2"><p id="p1059mcpsimp"><a name="p1059mcpsimp"></a><a name="p1059mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27.07%" id="mcps1.2.4.1.3"><p id="p1061mcpsimp"><a name="p1061mcpsimp"></a><a name="p1061mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row1062mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p1064mcpsimp"><a name="p1064mcpsimp"></a><a name="p1064mcpsimp"></a>uid</p>
</td>
<td class="cellrowborder" valign="top" width="51.93%" headers="mcps1.2.4.1.2 "><p id="p14138191243"><a name="p14138191243"></a><a name="p14138191243"></a>Specifies the ID of the target user.</p>
</td>
<td class="cellrowborder" valign="top" width="27.07%" headers="mcps1.2.4.1.3 "><a name="ul14151675449"></a><a name="ul14151675449"></a><ul id="ul14151675449"><li>Left blank</li><li>[0,60000]</li></ul>
</td>
</tr>
<tr id="row172161126124218"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p12217026154215"><a name="p12217026154215"></a><a name="p12217026154215"></a>gid</p>
</td>
<td class="cellrowborder" valign="top" width="51.93%" headers="mcps1.2.4.1.2 "><p id="p48748461789"><a name="p48748461789"></a><a name="p48748461789"></a>Specifies the ID of the target user group.</p>
</td>
<td class="cellrowborder" valign="top" width="27.07%" headers="mcps1.2.4.1.3 "><a name="ul10433713134417"></a><a name="ul10433713134417"></a><ul id="ul10433713134417"><li>Left blank</li><li>[0,60000]</li></ul>
</td>
</tr>
</tbody>
</table>
## Usage Guidelines
## Usage<a name="section14615155610719"></a>
- If no parameter is specified, the **su** command switches to user **root** by default. The **uid** and **gid** for user **root** are both **0**.
- If no parameter is specified, the **su** command switches to user **root** by default. The **uid** and **gid** for user **root** are both **0**.
- If **uid** and **gid** are specified, this command allows commands to be executed as the user with the specified **uid** and **gid**.
- If the input parameter is out of the range, an error message will be printed.
- If **uid** and **gid** are specified, this command allows commands to be executed as the user with the specified **uid** and **gid**.
## Example<a name="section13338150985"></a>
- If the input parameter is out of the range, an error message will be printed.
Run **su 1000 1000**.
## Output<a name="section125021924194613"></a>
## Example
Switching to the user with both **uid** and **gid** of **1000**:
Run **su 1000 1000**.
## Output
The user with both **uid** and **gid** of **1000** is switched.
```
OHOS # ls
......@@ -63,4 +50,3 @@ Directory /data/system/param:
-rw-r--r-- O u:1000 g:1000 hello 2.txt
-гw-r--r-- 0 u:0 g:0 hello_1.txt
```
# swtmr
## Command Function<a name="section166171064814"></a>
## Command Function
This command is used to query information about system software timers.
## Syntax<a name="section424011111682"></a>
swtmr \[_ID_\]
## Syntax
## Parameters<a name="section1268410459465"></a>
swtmr [_ID_]
**Table 1** Parameter description
<a name="table517mcpsimp"></a>
<table><thead align="left"><tr id="row523mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p525mcpsimp"><a name="p525mcpsimp"></a><a name="p525mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p527mcpsimp"><a name="p527mcpsimp"></a><a name="p527mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p529mcpsimp"><a name="p529mcpsimp"></a><a name="p529mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row530mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p532mcpsimp"><a name="p532mcpsimp"></a><a name="p532mcpsimp"></a>ID</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p534mcpsimp"><a name="p534mcpsimp"></a><a name="p534mcpsimp"></a>Specifies the ID of a software timer.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p536mcpsimp"><a name="p536mcpsimp"></a><a name="p536mcpsimp"></a>[0,0xFFFFFFFF]</p>
</td>
</tr>
</tbody>
</table>
## Parameters
## Usage<a name="section169806213815"></a>
**Table 1** Parameter description
- If no parameter is specified, information about all software timers is displayed.
- If the **ID** parameter is specified, information about the specified software timer is displayed.
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| ID | Specifies the ID of a software timer.| [0, 0xFFFFFFFF] |
## Example<a name="section16676026389"></a>
## Usage Guidelines
- If no parameter is specified, information about all software timers is displayed.
- If the **ID** parameter is specified, information about the specified software timer is displayed.
## Example
Run the following commands:
- swtmr
- swtmr 1
- swtmr
- swtmr 1
## Output<a name="section1541991614710"></a>
## Output
Example 1: information about all software timers
......@@ -76,56 +68,19 @@ SwTmrID State Mode Interval Count Arg handlerAddr
0x00000001 Ticking Period 1000 841 0x00000000 0x4037fc04
```
**Table 2** Output
<a name="table551mcpsimp"></a>
<table><thead align="left"><tr id="row556mcpsimp"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p558mcpsimp"><a name="p558mcpsimp"></a><a name="p558mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p560mcpsimp"><a name="p560mcpsimp"></a><a name="p560mcpsimp"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row561mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p563mcpsimp"><a name="p563mcpsimp"></a><a name="p563mcpsimp"></a>SwTmrID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p565mcpsimp"><a name="p565mcpsimp"></a><a name="p565mcpsimp"></a>ID of the software timer</p>
</td>
</tr>
<tr id="row566mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p568mcpsimp"><a name="p568mcpsimp"></a><a name="p568mcpsimp"></a>State</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p570mcpsimp"><a name="p570mcpsimp"></a><a name="p570mcpsimp"></a>Status of the software timer</p>
<p id="p88402543474"><a name="p88402543474"></a><a name="p88402543474"></a>The value can be <strong id="b164905263633836"><a name="b164905263633836"></a><a name="b164905263633836"></a>UnUsed</strong>, <strong id="b138979237833836"><a name="b138979237833836"></a><a name="b138979237833836"></a>Created</strong>, or <strong id="b3849463233836"><a name="b3849463233836"></a><a name="b3849463233836"></a>Ticking</strong>.</p>
</td>
</tr>
<tr id="row571mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p573mcpsimp"><a name="p573mcpsimp"></a><a name="p573mcpsimp"></a>Mode</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p575mcpsimp"><a name="p575mcpsimp"></a><a name="p575mcpsimp"></a>Mode of the software timer</p>
<p id="p657320204499"><a name="p657320204499"></a><a name="p657320204499"></a>The value can be <strong id="b201632419733836"><a name="b201632419733836"></a><a name="b201632419733836"></a>Once</strong>, <strong id="b45281151733836"><a name="b45281151733836"></a><a name="b45281151733836"></a>Period</strong>, or <strong id="b73443815433836"><a name="b73443815433836"></a><a name="b73443815433836"></a>NSD</strong> (one-shot timer that will not be automatically deleted after the timer has expired).</p>
</td>
</tr>
<tr id="row576mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p578mcpsimp"><a name="p578mcpsimp"></a><a name="p578mcpsimp"></a>Interval</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p580mcpsimp"><a name="p580mcpsimp"></a><a name="p580mcpsimp"></a>Number of ticks for the software timer</p>
</td>
</tr>
<tr id="row581mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p583mcpsimp"><a name="p583mcpsimp"></a><a name="p583mcpsimp"></a>Count</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p585mcpsimp"><a name="p585mcpsimp"></a><a name="p585mcpsimp"></a>Number of times that the software timer has been used</p>
</td>
</tr>
<tr id="row586mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p588mcpsimp"><a name="p588mcpsimp"></a><a name="p588mcpsimp"></a>Arg</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p590mcpsimp"><a name="p590mcpsimp"></a><a name="p590mcpsimp"></a>Input parameter</p>
</td>
</tr>
<tr id="row591mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p593mcpsimp"><a name="p593mcpsimp"></a><a name="p593mcpsimp"></a>handlerAddr</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p595mcpsimp"><a name="p595mcpsimp"></a><a name="p595mcpsimp"></a>Address of the callback</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE:**
>- The **ID** value can be in decimal or hexadecimal format.
>- If the **ID** value is within the range of \[0, _Number of current software timers - 1_\], the status of the specified software timer is returned. For other values, an error message is displayed.
**Table 2** Output description
| Parameter| Description|
| -------- | -------- |
| SwTmrID | ID of the software timer.|
| State | Status of the software timer.<br>The status may be **UnUsed**, **Created**, or **Ticking**.|
| Mode | Mode of the software timer.<br>The value can be **Once**, **Period**, or **NSD** (one-shot timer that will not be automatically deleted after the timer has expired).|
| Interval | Number of ticks for the software timer.|
| Count | Number of times that the software timer has been used.|
| Arg | Input parameter.|
| handlerAddr | Address of the callback.|
> **NOTE**<br>
> - The **ID** value can be in decimal or hexadecimal format.
>
> - If the **ID** value is within the range of [0, *Number of current software timers - 1*], the status of the specified software timer is returned. Otherwise, an error code is returned.
# systeminfo
## Command Function<a name="section863016434820"></a>
## Command Function
This command is used to display the resource usage of the current operating system, including tasks, semaphores, mutexes, queues, and software timers.
## Syntax<a name="section139791817795"></a>
## Syntax
systeminfo
## Parameters<a name="section19472339164813"></a>
None
## Parameters
None.
## Usage<a name="section285522592"></a>
## Usage Guidelines
None
None.
## Example<a name="section9471171015105"></a>
Run **systeminfo**.
## Example
## Output<a name="section1657011114915"></a>
Run **systeminfo**.
## Output
Usage of system resources:
......@@ -34,60 +40,15 @@ OHOS:/$ systeminfo
SwTmr 20 1024 YES
```
**Table 1** Output
<a name="table633mcpsimp"></a>
<table><thead align="left"><tr id="row638mcpsimp"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p640mcpsimp"><a name="p640mcpsimp"></a><a name="p640mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p642mcpsimp"><a name="p642mcpsimp"></a><a name="p642mcpsimp"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row643mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p645mcpsimp"><a name="p645mcpsimp"></a><a name="p645mcpsimp"></a>Module</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p647mcpsimp"><a name="p647mcpsimp"></a><a name="p647mcpsimp"></a>Module name</p>
</td>
</tr>
<tr id="row648mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p650mcpsimp"><a name="p650mcpsimp"></a><a name="p650mcpsimp"></a>Used</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p652mcpsimp"><a name="p652mcpsimp"></a><a name="p652mcpsimp"></a>Used resources</p>
</td>
</tr>
<tr id="row653mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p655mcpsimp"><a name="p655mcpsimp"></a><a name="p655mcpsimp"></a>Total</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p657mcpsimp"><a name="p657mcpsimp"></a><a name="p657mcpsimp"></a>Total resources</p>
</td>
</tr>
<tr id="row658mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p660mcpsimp"><a name="p660mcpsimp"></a><a name="p660mcpsimp"></a>Enabled</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p662mcpsimp"><a name="p662mcpsimp"></a><a name="p662mcpsimp"></a>Whether the module is enabled</p>
</td>
</tr>
<tr id="row10101624938"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p610724734"><a name="p610724734"></a><a name="p610724734"></a>Task</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1510024539"><a name="p1510024539"></a><a name="p1510024539"></a>Task</p>
</td>
</tr>
<tr id="row207288271839"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p572872713317"><a name="p572872713317"></a><a name="p572872713317"></a>Sem</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p272852716315"><a name="p272852716315"></a><a name="p272852716315"></a>Semaphore</p>
</td>
</tr>
<tr id="row1774316321731"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p274343218317"><a name="p274343218317"></a><a name="p274343218317"></a>Mutex</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1974319321133"><a name="p1974319321133"></a><a name="p1974319321133"></a>Mutex</p>
</td>
</tr>
<tr id="row121618371536"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p0161183720314"><a name="p0161183720314"></a><a name="p0161183720314"></a>Queue</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p09295155511"><a name="p09295155511"></a><a name="p09295155511"></a>Message queue</p>
</td>
</tr>
<tr id="row4935152211518"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p13935222154"><a name="p13935222154"></a><a name="p13935222154"></a>SwTmr</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p0936182215515"><a name="p0936182215515"></a><a name="p0936182215515"></a>Software timer</p>
</td>
</tr>
</tbody>
</table>
**Table 1** Output description
| Parameter | Description |
| ------- | -------------- |
| Module | Module name. |
| Used | Used resources. |
| Total | Total resources. |
| Enabled | Whether the module is enabled.|
| Task | Task. |
| Sem | Semaphore. |
| Queue | Using queues. |
| SwTmr | Software timer. |
# task
## Command Function<a name="section0533181714106"></a>
## Command Function
This command is used to query information about processes and threads.
## Syntax<a name="section1014412308101"></a>
## Syntax
task/task -a
## Parameters<a name="section116057158506"></a>
**Table 1** Parameter description
<a name="table672mcpsimp"></a>
<table><thead align="left"><tr id="row678mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p680mcpsimp"><a name="p680mcpsimp"></a><a name="p680mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p682mcpsimp"><a name="p682mcpsimp"></a><a name="p682mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p684mcpsimp"><a name="p684mcpsimp"></a><a name="p684mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row685mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p687mcpsimp"><a name="p687mcpsimp"></a><a name="p687mcpsimp"></a>-a</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p689mcpsimp"><a name="p689mcpsimp"></a><a name="p689mcpsimp"></a>Displays all information.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p691mcpsimp"><a name="p691mcpsimp"></a><a name="p691mcpsimp"></a>N/A</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section2053502951112"></a>
## Parameters
**Table 1** Parameter description
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| -a | Displays all information.| N/A |
## Usage Guidelines
If no parameter is specified, partial task information is displayed by default.
## Example<a name="section12629113381116"></a>
Run **task**.
## Example
Run **task**.
## Output<a name="section19299103465015"></a>
Task information \(partial\):
## Output
Task information (partial):
```
OHOS # task
......@@ -55,6 +46,7 @@ OHOS # task
6 1 6 0 Pending 0x688000 0x137000 0x11c518 0.0 media_server
7 1 7 0 Pending 0x9d2000 0x103000 0xa1ddf 0.89 wms_server
8 1 1 1000 Running 0x2bf000 0x8f000 0x2a8c6 0.0 shell
9 5 5 101 Pending 0x11ea000 0x2f9000 0x20429d 0.97 com.example.launcher
11 1 11 0 Pending 0x4d4000 0x112000 0xe0ad7 0.0 deviceauth_service
12 1 12 0 Pending 0x34f000 0xbd000 0x519ee 0.0 sensor_service
13 1 13 2 Pending 0x34e000 0xb3000 0x523d9 0.0 ai_server
......@@ -68,75 +60,19 @@ OHOS # task
7 2 0x3 -1 Pending 0x4e20 0xa5c 0.0 0 PlatformWorkerThread
```
**Table 2** Output
<a name="table809mcpsimp"></a>
<table><thead align="left"><tr id="row814mcpsimp"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p816mcpsimp"><a name="p816mcpsimp"></a><a name="p816mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p818mcpsimp"><a name="p818mcpsimp"></a><a name="p818mcpsimp"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row20360171311398"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p123611139397"><a name="p123611139397"></a><a name="p123611139397"></a>PID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3361171333920"><a name="p3361171333920"></a><a name="p3361171333920"></a>Process ID</p>
</td>
</tr>
<tr id="row262535153913"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p862625163918"><a name="p862625163918"></a><a name="p862625163918"></a>PPID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1062611511398"><a name="p1062611511398"></a><a name="p1062611511398"></a>Parent process ID</p>
</td>
</tr>
<tr id="row9683953153916"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p76831753103915"><a name="p76831753103915"></a><a name="p76831753103915"></a>PGID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p2068355383916"><a name="p2068355383916"></a><a name="p2068355383916"></a>Process group ID</p>
</td>
</tr>
<tr id="row85721136402"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p8572151313402"><a name="p8572151313402"></a><a name="p8572151313402"></a>UID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p55721813164013"><a name="p55721813164013"></a><a name="p55721813164013"></a>User ID</p>
</td>
</tr>
<tr id="row19180126151415"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p836mcpsimp"><a name="p836mcpsimp"></a><a name="p836mcpsimp"></a>Status</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p838mcpsimp"><a name="p838mcpsimp"></a><a name="p838mcpsimp"></a>Current task status</p>
</td>
</tr>
<tr id="row511517331702"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p2116833506"><a name="p2116833506"></a><a name="p2116833506"></a>CPUUSE10s</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p2011611331604"><a name="p2011611331604"></a><a name="p2011611331604"></a>CPU usage within last 10 seconds</p>
</td>
</tr>
<tr id="row136191839311"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p66199397110"><a name="p66199397110"></a><a name="p66199397110"></a>PName</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p11619153916110"><a name="p11619153916110"></a><a name="p11619153916110"></a>Process name</p>
</td>
</tr>
<tr id="row824mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p826mcpsimp"><a name="p826mcpsimp"></a><a name="p826mcpsimp"></a>TID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p828mcpsimp"><a name="p828mcpsimp"></a><a name="p828mcpsimp"></a>Task ID</p>
</td>
</tr>
<tr id="row839mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p841mcpsimp"><a name="p841mcpsimp"></a><a name="p841mcpsimp"></a>StackSize</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p843mcpsimp"><a name="p843mcpsimp"></a><a name="p843mcpsimp"></a>Size of the task stack</p>
</td>
</tr>
<tr id="row844mcpsimp"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p846mcpsimp"><a name="p846mcpsimp"></a><a name="p846mcpsimp"></a>WaterLine</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p848mcpsimp"><a name="p848mcpsimp"></a><a name="p848mcpsimp"></a>Peak value of the stack used</p>
</td>
</tr>
<tr id="row10188146131813"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p218912671818"><a name="p218912671818"></a><a name="p218912671818"></a>MEMUSE</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1518926151810"><a name="p1518926151810"></a><a name="p1518926151810"></a>Memory usage</p>
</td>
</tr>
<tr id="row45465584313"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p821mcpsimp"><a name="p821mcpsimp"></a><a name="p821mcpsimp"></a>TaskName</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p823mcpsimp"><a name="p823mcpsimp"></a><a name="p823mcpsimp"></a>Task name</p>
</td>
</tr>
</tbody>
</table>
**Table 2** Output description
| Parameter| Description|
| -------- | -------- |
| PID | Process ID.|
| PPID | Parent process ID.|
| PGID | Process group ID.|
| UID | User ID.|
| Status | Current task status.|
| CPUUSE10s | CPU usage within last 10 seconds.|
| PName | Name of the process.|
| TID | Task ID.|
| StackSize | Size of the task stack.|
| WaterLine | Peak value of the stack used.|
| MEMUSE | Memory usage.|
| TaskName | Task name.|
# top
## Command Function<a name="section20643141481314"></a>
## Command Function
This command is used to query process and thread information.
## Syntax<a name="section1075441721316"></a>
top \[_-a_\]
## Parameters<a name="section1472810220135"></a>
**Table 1** Parameter description
<a name="table966mcpsimp"></a>
<table><thead align="left"><tr id="row973mcpsimp"><th class="cellrowborder" valign="top" width="19.801980198019802%" id="mcps1.2.5.1.1"><p id="p975mcpsimp"><a name="p975mcpsimp"></a><a name="p975mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="29.222922292229224%" id="mcps1.2.5.1.2"><p id="p977mcpsimp"><a name="p977mcpsimp"></a><a name="p977mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="22.26222622262226%" id="mcps1.2.5.1.3"><p id="p979mcpsimp"><a name="p979mcpsimp"></a><a name="p979mcpsimp"></a>Default Value</p>
</th>
<th class="cellrowborder" valign="top" width="28.712871287128717%" id="mcps1.2.5.1.4"><p id="p981mcpsimp"><a name="p981mcpsimp"></a><a name="p981mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row1643213388538"><td class="cellrowborder" valign="top" width="19.801980198019802%" headers="mcps1.2.5.1.1 "><p id="p11426113820531"><a name="p11426113820531"></a><a name="p11426113820531"></a>--help</p>
</td>
<td class="cellrowborder" valign="top" width="29.222922292229224%" headers="mcps1.2.5.1.2 "><p id="p942673885313"><a name="p942673885313"></a><a name="p942673885313"></a>Displays the parameters supported by the <strong id="b2435956125215"><a name="b2435956125215"></a><a name="b2435956125215"></a>top</strong> command.</p>
</td>
<td class="cellrowborder" valign="top" width="22.26222622262226%" headers="mcps1.2.5.1.3 "><p id="p9426538195319"><a name="p9426538195319"></a><a name="p9426538195319"></a>N/A</p>
</td>
<td class="cellrowborder" valign="top" width="28.712871287128717%" headers="mcps1.2.5.1.4 ">&nbsp;&nbsp;</td>
</tr>
<tr id="row1943253865311"><td class="cellrowborder" valign="top" width="19.801980198019802%" headers="mcps1.2.5.1.1 "><p id="p1542613812537"><a name="p1542613812537"></a><a name="p1542613812537"></a>-a</p>
</td>
<td class="cellrowborder" valign="top" width="29.222922292229224%" headers="mcps1.2.5.1.2 "><p id="p1842663895320"><a name="p1842663895320"></a><a name="p1842663895320"></a>Displays detailed information.</p>
</td>
<td class="cellrowborder" valign="top" width="22.26222622262226%" headers="mcps1.2.5.1.3 "><p id="p13426123815313"><a name="p13426123815313"></a><a name="p13426123815313"></a>N/A</p>
</td>
<td class="cellrowborder" valign="top" width="28.712871287128717%" headers="mcps1.2.5.1.4 ">&nbsp;&nbsp;</td>
</tr>
</tbody>
</table>
## Usage<a name="section186772414131"></a>
If no parameter is specified, this command displays process and thread information of some tasks by default.
## Example<a name="section4764192791314"></a>
Run **top**.
## Output<a name="section5791253155517"></a>
## Syntax
top [_-a_]
## Parameters
**Table 1** Parameter description
| Parameter | Description |
| ------ | --------------------------- |
| --help | Displays the parameters supported by the **top** command.|
| -a | Displays detailed information. |
## Usage Guidelines
If no parameter is specified, partial task information is displayed by default.
## Note
Currently, the shell does not support this command. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
## Example
Run **top**.
## Output
Command output
......@@ -97,75 +81,19 @@ OHOS:/$ top
64 2 0x3 -1 Pending 0x4000 0x244 0.0 0 USB_NGIAN_BULK_TasK
```
**Table 2** Output description
<a name="table1522165195511"></a>
<table><thead align="left"><tr id="row1952285165514"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p25224518556"><a name="p25224518556"></a><a name="p25224518556"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p16522852554"><a name="p16522852554"></a><a name="p16522852554"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row207354303550"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p107238309551"><a name="p107238309551"></a><a name="p107238309551"></a>PID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p372373015515"><a name="p372373015515"></a><a name="p372373015515"></a>Process ID</p>
</td>
</tr>
<tr id="row1373513035514"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p972343012551"><a name="p972343012551"></a><a name="p972343012551"></a>PPID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p19723153055519"><a name="p19723153055519"></a><a name="p19723153055519"></a>Parent process ID</p>
</td>
</tr>
<tr id="row16735133035518"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p14723153065514"><a name="p14723153065514"></a><a name="p14723153065514"></a>PGID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p117231630165519"><a name="p117231630165519"></a><a name="p117231630165519"></a>Process group ID</p>
</td>
</tr>
<tr id="row157354306558"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p3723430195510"><a name="p3723430195510"></a><a name="p3723430195510"></a>UID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1372373016559"><a name="p1372373016559"></a><a name="p1372373016559"></a>User ID</p>
</td>
</tr>
<tr id="row573515301555"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1472318308552"><a name="p1472318308552"></a><a name="p1472318308552"></a>Status</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p57231430165518"><a name="p57231430165518"></a><a name="p57231430165518"></a>Current task status</p>
</td>
</tr>
<tr id="row15735730135515"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p472363045510"><a name="p472363045510"></a><a name="p472363045510"></a>CPUUSE10s</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1172323019556"><a name="p1172323019556"></a><a name="p1172323019556"></a>CPU usage within last 10 seconds</p>
</td>
</tr>
<tr id="row16735163025519"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p10723183035516"><a name="p10723183035516"></a><a name="p10723183035516"></a>PName</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1472310309557"><a name="p1472310309557"></a><a name="p1472310309557"></a>Process name</p>
</td>
</tr>
<tr id="row973593017554"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p13724123075515"><a name="p13724123075515"></a><a name="p13724123075515"></a>TID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p12724630135510"><a name="p12724630135510"></a><a name="p12724630135510"></a>Task ID</p>
</td>
</tr>
<tr id="row157341730135512"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p87241930135520"><a name="p87241930135520"></a><a name="p87241930135520"></a>StackSize</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p8724930135519"><a name="p8724930135519"></a><a name="p8724930135519"></a>Size of the task stack</p>
</td>
</tr>
<tr id="row187341330145517"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1172483055520"><a name="p1172483055520"></a><a name="p1172483055520"></a>WaterLine</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p10724103013559"><a name="p10724103013559"></a><a name="p10724103013559"></a>Peak value of the stack used</p>
</td>
</tr>
<tr id="row473473025513"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p87240306554"><a name="p87240306554"></a><a name="p87240306554"></a>MEMUSE</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p10724123005519"><a name="p10724123005519"></a><a name="p10724123005519"></a>Memory usage</p>
</td>
</tr>
<tr id="row18734143035519"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p7724163011559"><a name="p7724163011559"></a><a name="p7724163011559"></a>TaskName</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p872414301552"><a name="p872414301552"></a><a name="p872414301552"></a>Task name</p>
</td>
</tr>
</tbody>
</table>
**Table 2** Output description
| Parameter | Description |
| --------- | ----------------- |
| PID | Process ID. |
| PPID | Parent process ID. |
| PGID | Process group ID. |
| UID | User ID. |
| Status | Current task status. |
| CPUUSE10s | CPU usage within last 10 seconds.|
| PName | Name of the process. |
| TID | Task ID. |
| StackSize | Size of the task stack. |
| WaterLine | Peak value of the stack used. |
| MEMUSE | Memory usage. |
| TaskName | Task name. |
# uname
## Command Function<a name="section107697383115"></a>
## Command Function
This command is used to display the name, version creation time, system name, and version information of the current operating system.
## Syntax<a name="section162824341116"></a>
uname \[_-a | -s | -r | -m | -n | -v | --help_\]
**Table 1** Parameters
<a name="table909mcpsimp"></a>
<table><thead align="left"><tr id="row914mcpsimp"><th class="cellrowborder" valign="top" width="33.989999999999995%" id="mcps1.2.3.1.1"><p id="p916mcpsimp"><a name="p916mcpsimp"></a><a name="p916mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="66.01%" id="mcps1.2.3.1.2"><p id="p918mcpsimp"><a name="p918mcpsimp"></a><a name="p918mcpsimp"></a>Parameters</p>
</th>
</tr>
</thead>
<tbody><tr id="row7659172561412"><td class="cellrowborder" valign="top" width="33.989999999999995%" headers="mcps1.2.3.1.1 "><p id="p9648112519147"><a name="p9648112519147"></a><a name="p9648112519147"></a>--help</p>
</td>
<td class="cellrowborder" valign="top" width="66.01%" headers="mcps1.2.3.1.2 "><p id="p1664862551411"><a name="p1664862551411"></a><a name="p1664862551411"></a>Displays help information.</p>
</td>
</tr>
<tr id="row365962510147"><td class="cellrowborder" valign="top" width="33.989999999999995%" headers="mcps1.2.3.1.1 "><p id="p26489259149"><a name="p26489259149"></a><a name="p26489259149"></a>No parameter</p>
</td>
<td class="cellrowborder" valign="top" width="66.01%" headers="mcps1.2.3.1.2 "><p id="p186484252141"><a name="p186484252141"></a><a name="p186484252141"></a>Displays the operating system name by default.</p>
</td>
</tr>
<tr id="row12659142511413"><td class="cellrowborder" valign="top" width="33.989999999999995%" headers="mcps1.2.3.1.1 "><p id="p156481253140"><a name="p156481253140"></a><a name="p156481253140"></a>-a</p>
</td>
<td class="cellrowborder" valign="top" width="66.01%" headers="mcps1.2.3.1.2 "><p id="p864872512145"><a name="p864872512145"></a><a name="p864872512145"></a>Displays all information.</p>
</td>
</tr>
<tr id="row365917254143"><td class="cellrowborder" valign="top" width="33.989999999999995%" headers="mcps1.2.3.1.1 "><p id="p136481625131417"><a name="p136481625131417"></a><a name="p136481625131417"></a>-s</p>
</td>
<td class="cellrowborder" valign="top" width="66.01%" headers="mcps1.2.3.1.2 "><p id="p1064852514149"><a name="p1064852514149"></a><a name="p1064852514149"></a>Displays the operating system name.</p>
</td>
</tr>
<tr id="row196591425101413"><td class="cellrowborder" valign="top" width="33.989999999999995%" headers="mcps1.2.3.1.1 "><p id="p364814255144"><a name="p364814255144"></a><a name="p364814255144"></a>-r</p>
</td>
<td class="cellrowborder" valign="top" width="66.01%" headers="mcps1.2.3.1.2 "><p id="p1564872515145"><a name="p1564872515145"></a><a name="p1564872515145"></a>Displays the kernel release version.</p>
</td>
</tr>
<tr id="row10659202591419"><td class="cellrowborder" valign="top" width="33.989999999999995%" headers="mcps1.2.3.1.1 "><p id="p11648162520146"><a name="p11648162520146"></a><a name="p11648162520146"></a>-m</p>
</td>
<td class="cellrowborder" valign="top" width="66.01%" headers="mcps1.2.3.1.2 "><p id="p136489251143"><a name="p136489251143"></a><a name="p136489251143"></a>Displays the operating system architecture name.</p>
</td>
</tr>
<tr id="row126582025111417"><td class="cellrowborder" valign="top" width="33.989999999999995%" headers="mcps1.2.3.1.1 "><p id="p13648102551411"><a name="p13648102551411"></a><a name="p13648102551411"></a>-n</p>
</td>
<td class="cellrowborder" valign="top" width="66.01%" headers="mcps1.2.3.1.2 "><p id="p6648132512141"><a name="p6648132512141"></a><a name="p6648132512141"></a>Displays the network domain name of the host.</p>
</td>
</tr>
<tr id="row3658925151415"><td class="cellrowborder" valign="top" width="33.989999999999995%" headers="mcps1.2.3.1.1 "><p id="p9648152501414"><a name="p9648152501414"></a><a name="p9648152501414"></a>-v</p>
</td>
<td class="cellrowborder" valign="top" width="66.01%" headers="mcps1.2.3.1.2 "><p id="p46489250149"><a name="p46489250149"></a><a name="p46489250149"></a>Displays version information.</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section2652124861114"></a>
- The **uname** command displays the name of the current operating system by default.
- Except **--help** and **-a**, other parameters can be used together. **uname -a** is equivalent to **uname -srmnv**.
## Example<a name="section0107995132"></a>
## Syntax
uname [_-a | -s | -r | -m | -n | -v | --help_]
**Table 1** Parameter description
| Parameter | Description |
| ------ | ----------------------- |
| --help | Displays help information.|
| No parameter| Displays the operating system name by default. |
| -a | Displays all data. |
| -s | Displays the operating system name. |
| -r | Displays the kernel release version. |
| -m | Displays the operating system architecture name. |
| -n | Displays the network domain name of the host. |
| -v | Displays version information. |
## Usage Guidelines
- The **uname** command displays the name of the current operating system by default.
- Except **--help** and **-a**, other parameters can be used together. **uname -a** is equivalent to **uname -srmnv**.
## Note
The **-r**, **-m**, and **-n** parameters are not supported currently. mksh supports these parameters. To switch to mksh, run **cd bin** and **./mksh**.
## Example
Run the following commands:
- uname -a
- uname -ms
- uname -a
- uname -ms
## Output<a name="section1215113245511"></a>
## Output
Example 1: all information of the operating system
```
OHOS:/$ uname -a
LiteOS hisilicon 2.0.x.x Huawei LiteOS 2.0.x.x Oct 21 2021 17:39:32 Cortex-A7
LiteOS hisilicon 2.0.0.37 LiteOS 2.0.0.37 Oct 21 2021 17:39:32 Cortex-A7
OHOS:/$
```
......@@ -89,4 +61,3 @@ OHOS:/$ uname -ms
LiteOS Cortex-A7
OHOS:/$
```
# vmm
## Command Function<a name="section445335110416"></a>
## Command Function
This command is used to query the virtual memory used by a process.
## Syntax<a name="section1795712553416"></a>
- vmm \[_-a / -h / --help_\]
- vmm \[_pid_\]
## Parameters<a name="section92544592410"></a>
**Table 1** Parameter description
<a name="table3900mcpsimp"></a>
<table><thead align="left"><tr id="row3906mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p3908mcpsimp"><a name="p3908mcpsimp"></a><a name="p3908mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p3910mcpsimp"><a name="p3910mcpsimp"></a><a name="p3910mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p3912mcpsimp"><a name="p3912mcpsimp"></a><a name="p3912mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row3913mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p17944444181717"><a name="p17944444181717"></a><a name="p17944444181717"></a>-a</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p209441344121716"><a name="p209441344121716"></a><a name="p209441344121716"></a>Displays the virtual memory usage of all processes.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3919mcpsimp"><a name="p3919mcpsimp"></a><a name="p3919mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row3920mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p1944124412171"><a name="p1944124412171"></a><a name="p1944124412171"></a>-h | --help</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p1494494441713"><a name="p1494494441713"></a><a name="p1494494441713"></a>Displays help information.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3926mcpsimp"><a name="p3926mcpsimp"></a><a name="p3926mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row3934mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p5945444181720"><a name="p5945444181720"></a><a name="p5945444181720"></a>pid</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p1594515442177"><a name="p1594515442177"></a><a name="p1594515442177"></a>Specifies the ID of the process to query.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p3940mcpsimp"><a name="p3940mcpsimp"></a><a name="p3940mcpsimp"></a>[0,63]</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section104151141252"></a>
## Syntax
- vmm [_-a / -h / --help_]
- vmm [_pid_]
## Parameters
**Table 1** Parameter description
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| -a | Displays the virtual memory usage of all processes.| N/A |
| -h&nbsp;\|&nbsp;--help | Displays help information.| N/A |
| pid | Specifies the ID of the process to query.| [0, 63] |
## Usage Guidelines
By default, this command displays the virtual memory usage of all processes.
## Example<a name="section11545171957"></a>
Run **vmm 3**.
## Example
## Output<a name="section075617368542"></a>
Run **vmm 3**.
## Output
Virtual memory usage of process 3:
......@@ -82,92 +62,25 @@ OHOS # vmm 3
0x408c3ce0 /lib/libc++.so 0x23cb0000 0x00001000 CH US RD WR 1 1
```
**Table 2** Basic process information
<a name="table17136143042317"></a>
<table><thead align="left"><tr id="row1113611307232"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p17137173017232"><a name="p17137173017232"></a><a name="p17137173017232"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p171371302230"><a name="p171371302230"></a><a name="p171371302230"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row11371230202317"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p0137630122313"><a name="p0137630122313"></a><a name="p0137630122313"></a>PID</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p513793016233"><a name="p513793016233"></a><a name="p513793016233"></a>Process ID</p>
</td>
</tr>
<tr id="row61371630112315"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p18137133019236"><a name="p18137133019236"></a><a name="p18137133019236"></a>aspace</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p9137130122311"><a name="p9137130122311"></a><a name="p9137130122311"></a>Address of the virtual memory control block</p>
</td>
</tr>
<tr id="row613793015232"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12137230172311"><a name="p12137230172311"></a><a name="p12137230172311"></a>name</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p19137193018235"><a name="p19137193018235"></a><a name="p19137193018235"></a>Process name</p>
</td>
</tr>
<tr id="row1613763019237"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1413723015233"><a name="p1413723015233"></a><a name="p1413723015233"></a>base</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1613783082319"><a name="p1613783082319"></a><a name="p1613783082319"></a>Start address of the virtual memory</p>
</td>
</tr>
<tr id="row141376308237"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p101371730162319"><a name="p101371730162319"></a><a name="p101371730162319"></a>size</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18137143092313"><a name="p18137143092313"></a><a name="p18137143092313"></a>Size of virtual memory</p>
</td>
</tr>
<tr id="row19137163072316"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p16137183013235"><a name="p16137183013235"></a><a name="p16137183013235"></a>pages</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p5137130142314"><a name="p5137130142314"></a><a name="p5137130142314"></a>Number of used physical pages</p>
</td>
</tr>
</tbody>
</table>
**Table 3** Virtual memory region information
<a name="table1195314682418"></a>
<table><thead align="left"><tr id="row14953144632413"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1195314617242"><a name="p1195314617242"></a><a name="p1195314617242"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p13953174614243"><a name="p13953174614243"></a><a name="p13953174614243"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row18953114610242"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p09531746132417"><a name="p09531746132417"></a><a name="p09531746132417"></a>region</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1795344642412"><a name="p1795344642412"></a><a name="p1795344642412"></a>Address of the control block in the virtual memory region</p>
</td>
</tr>
<tr id="row1795384682411"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p199531846112417"><a name="p199531846112417"></a><a name="p199531846112417"></a>name</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p19539466245"><a name="p19539466245"></a><a name="p19539466245"></a>Name of the virtual memory region</p>
</td>
</tr>
<tr id="row99531446132410"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p139531946132417"><a name="p139531946132417"></a><a name="p139531946132417"></a>base</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p139536468242"><a name="p139536468242"></a><a name="p139536468242"></a>Start address of the virtual memory region</p>
</td>
</tr>
<tr id="row79531046122418"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11953546102418"><a name="p11953546102418"></a><a name="p11953546102418"></a>size</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p89531246142419"><a name="p89531246142419"></a><a name="p89531246142419"></a>Size of the virtual memory region</p>
</td>
</tr>
<tr id="row1295315464240"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p7953154602419"><a name="p7953154602419"></a><a name="p7953154602419"></a>mmu_flags</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p395464620242"><a name="p395464620242"></a><a name="p395464620242"></a>MMU mapping attribute of the virtual memory region</p>
</td>
</tr>
<tr id="row10954154692413"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1195484642410"><a name="p1195484642410"></a><a name="p1195484642410"></a>pages</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p29541546112416"><a name="p29541546112416"></a><a name="p29541546112416"></a>Number of used physical pages, including that of the shared memory</p>
</td>
</tr>
<tr id="row1395411463246"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p14954146152418"><a name="p14954146152418"></a><a name="p14954146152418"></a>pg/ref</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p10954164642419"><a name="p10954164642419"></a><a name="p10954164642419"></a>Number of used physical pages</p>
</td>
</tr>
</tbody>
</table>
**Table 2** Basic process information
| Parameter| Description|
| -------- | -------- |
| PID | Process ID.|
| aspace | Address of the virtual memory control block.|
| name | Process name.|
| base | Start address of the virtual memory.|
| size | Total Virtual Memory.|
| pages | Number of used physical pages.|
**Table 3** Virtual memory interval information
| Parameter| Description|
| -------- | -------- |
| region | Address of the control block in the virtual memory region.|
| name | Name of the virtual memory region.|
| base | Start address of the virtual memory region.|
| size | Size of the virtual memory region.|
| mmu_flags | MMU mapping attribute of the virtual memory region.|
| pages | Number of used physical pages, including that of the shared memory.|
| pg/ref | Number of used physical pages.|
# watch
## Command Function<a name="section20643141481314"></a>
## Command Function
This command is used to periodically run the specified command and display its execution result.
## Syntax<a name="section1075441721316"></a>
- watch
- watch \[_-c/-n/-t/--count/--interval/-no-title/--over_\] \[_command_\]
## Parameters<a name="section1472810220135"></a>
**Table 1** Parameter description
<a name="table966mcpsimp"></a>
<table><thead align="left"><tr id="row973mcpsimp"><th class="cellrowborder" valign="top" width="19.801980198019802%" id="mcps1.2.5.1.1"><p id="p975mcpsimp"><a name="p975mcpsimp"></a><a name="p975mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="29.222922292229224%" id="mcps1.2.5.1.2"><p id="p977mcpsimp"><a name="p977mcpsimp"></a><a name="p977mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="22.26222622262226%" id="mcps1.2.5.1.3"><p id="p979mcpsimp"><a name="p979mcpsimp"></a><a name="p979mcpsimp"></a>Default Value</p>
</th>
<th class="cellrowborder" valign="top" width="28.712871287128717%" id="mcps1.2.5.1.4"><p id="p981mcpsimp"><a name="p981mcpsimp"></a><a name="p981mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row982mcpsimp"><td class="cellrowborder" valign="top" width="19.801980198019802%" headers="mcps1.2.5.1.1 "><p id="p984mcpsimp"><a name="p984mcpsimp"></a><a name="p984mcpsimp"></a>-c / --count</p>
</td>
<td class="cellrowborder" valign="top" width="29.222922292229224%" headers="mcps1.2.5.1.2 "><p id="p986mcpsimp"><a name="p986mcpsimp"></a><a name="p986mcpsimp"></a>Specifies the number of times that the specified command is executed.</p>
</td>
<td class="cellrowborder" valign="top" width="22.26222622262226%" headers="mcps1.2.5.1.3 "><p id="p988mcpsimp"><a name="p988mcpsimp"></a><a name="p988mcpsimp"></a>0xFFFFFF</p>
</td>
<td class="cellrowborder" valign="top" width="28.712871287128717%" headers="mcps1.2.5.1.4 "><p id="p990mcpsimp"><a name="p990mcpsimp"></a><a name="p990mcpsimp"></a>(0, 0xFFFFFF]</p>
</td>
</tr>
<tr id="row991mcpsimp"><td class="cellrowborder" valign="top" width="19.801980198019802%" headers="mcps1.2.5.1.1 "><p id="p993mcpsimp"><a name="p993mcpsimp"></a><a name="p993mcpsimp"></a>-n / --interval</p>
</td>
<td class="cellrowborder" valign="top" width="29.222922292229224%" headers="mcps1.2.5.1.2 "><p id="p995mcpsimp"><a name="p995mcpsimp"></a><a name="p995mcpsimp"></a>Specifies the interval (in seconds) for periodically running the specified command.</p>
</td>
<td class="cellrowborder" valign="top" width="22.26222622262226%" headers="mcps1.2.5.1.3 "><p id="p997mcpsimp"><a name="p997mcpsimp"></a><a name="p997mcpsimp"></a>1s</p>
</td>
<td class="cellrowborder" valign="top" width="28.712871287128717%" headers="mcps1.2.5.1.4 "><p id="p999mcpsimp"><a name="p999mcpsimp"></a><a name="p999mcpsimp"></a>(0, 0xFFFFFF]</p>
</td>
</tr>
<tr id="row1000mcpsimp"><td class="cellrowborder" valign="top" width="19.801980198019802%" headers="mcps1.2.5.1.1 "><p id="p1002mcpsimp"><a name="p1002mcpsimp"></a><a name="p1002mcpsimp"></a>-t / -no-title</p>
</td>
<td class="cellrowborder" valign="top" width="29.222922292229224%" headers="mcps1.2.5.1.2 "><p id="p1004mcpsimp"><a name="p1004mcpsimp"></a><a name="p1004mcpsimp"></a>Disables time display on the top.</p>
</td>
<td class="cellrowborder" valign="top" width="22.26222622262226%" headers="mcps1.2.5.1.3 "><p id="p1006mcpsimp"><a name="p1006mcpsimp"></a><a name="p1006mcpsimp"></a>N/A</p>
</td>
<td class="cellrowborder" valign="top" width="28.712871287128717%" headers="mcps1.2.5.1.4 "><p id="p1008mcpsimp"><a name="p1008mcpsimp"></a><a name="p1008mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row1009mcpsimp"><td class="cellrowborder" valign="top" width="19.801980198019802%" headers="mcps1.2.5.1.1 "><p id="p1011mcpsimp"><a name="p1011mcpsimp"></a><a name="p1011mcpsimp"></a>command</p>
</td>
<td class="cellrowborder" valign="top" width="29.222922292229224%" headers="mcps1.2.5.1.2 "><p id="p1013mcpsimp"><a name="p1013mcpsimp"></a><a name="p1013mcpsimp"></a>Specifies the command to be monitored.</p>
</td>
<td class="cellrowborder" valign="top" width="22.26222622262226%" headers="mcps1.2.5.1.3 "><p id="p1015mcpsimp"><a name="p1015mcpsimp"></a><a name="p1015mcpsimp"></a>N/A</p>
</td>
<td class="cellrowborder" valign="top" width="28.712871287128717%" headers="mcps1.2.5.1.4 "><p id="p1017mcpsimp"><a name="p1017mcpsimp"></a><a name="p1017mcpsimp"></a>N/A</p>
</td>
</tr>
<tr id="row1018mcpsimp"><td class="cellrowborder" valign="top" width="19.801980198019802%" headers="mcps1.2.5.1.1 "><p id="p1020mcpsimp"><a name="p1020mcpsimp"></a><a name="p1020mcpsimp"></a>--over</p>
</td>
<td class="cellrowborder" valign="top" width="29.222922292229224%" headers="mcps1.2.5.1.2 "><p id="p1022mcpsimp"><a name="p1022mcpsimp"></a><a name="p1022mcpsimp"></a>Stops the current command monitoring.</p>
</td>
<td class="cellrowborder" valign="top" width="22.26222622262226%" headers="mcps1.2.5.1.3 "><p id="p1024mcpsimp"><a name="p1024mcpsimp"></a><a name="p1024mcpsimp"></a>N/A</p>
</td>
<td class="cellrowborder" valign="top" width="28.712871287128717%" headers="mcps1.2.5.1.4 "><p id="p1026mcpsimp"><a name="p1026mcpsimp"></a><a name="p1026mcpsimp"></a>N/A</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section186772414131"></a>
You can run the **watch --over** command to stop monitoring of the specified command.
## Example<a name="section4764192791314"></a>
Run **watch -n 2 -c 6 task**.
## Output<a name="section5791253155517"></a>
Example: The **task** command is executed six times at an interval of 2 seconds.
## Syntax
- watch
- watch [_-c/-n/-t/--count/--interval/-no-title/--over_] [_command_]
## Parameters
**Table 1** Parameter description
| Parameter| Description| Default Value| Value Range|
| -------- | -------- | -------- | -------- |
| -c&nbsp;/&nbsp;--count | Specifies the number of times that the specified command is executed.| 0xFFFFFF | (0, 0xFFFFFF]|
| -n&nbsp;/&nbsp;--interval | Specifies the interval for running the command, in seconds.| 1s | (0, 0xFFFFFF]|
| -t&nbsp;/&nbsp;-no-title | Disables time display on the top.| N/A | N/A |
| command | Specifies the command to be monitored.| N/A | N/A |
| --over | Stops the current command monitoring.| N/A | N/A |
## Usage Guidelines
You can run the **watch --over** command to stop monitoring of the specified command.
## Example
Run **watch -n 2 -c 6 task**.
## Output
Example: The **task** command is executed six times at an interval of 2 seconds.
```
OHOS # watch -n 2 -c 6 task
......@@ -121,4 +77,3 @@ OHOS #
17 2 0x3 0 Running 0x3000 0x73c 0.0 0 shellcmd_watch
18 2 0x3 -1 Pending 0x2710 0x3ac 0.0 0 GPIO_IRQ_TSK_0_4
```
# cat
## Command Function<a name="section16710153391315"></a>
## Command Function
This command is used to display the content of a text file.
## Syntax<a name="section1699392313158"></a>
cat \[_pathname_\]
## Syntax
cat [_pathname_]
## Parameters<a name="section1677217374136"></a>
## Parameters
**Table 1** Parameter description
**Table 1** Parameter description
<a name="table1049mcpsimp"></a>
<table><thead align="left"><tr id="row1055mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p1057mcpsimp"><a name="p1057mcpsimp"></a><a name="p1057mcpsimp"></a><strong id="b2166111484619"><a name="b2166111484619"></a><a name="b2166111484619"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p1059mcpsimp"><a name="p1059mcpsimp"></a><a name="p1059mcpsimp"></a><strong id="b17121718469"><a name="b17121718469"></a><a name="b17121718469"></a>Description</strong></p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p1061mcpsimp"><a name="p1061mcpsimp"></a><a name="p1061mcpsimp"></a><strong id="b6990101716464"><a name="b6990101716464"></a><a name="b6990101716464"></a>Value Range</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1062mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p1064mcpsimp"><a name="p1064mcpsimp"></a><a name="p1064mcpsimp"></a>pathname</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p1066mcpsimp"><a name="p1066mcpsimp"></a><a name="p1066mcpsimp"></a>Specifies the file path.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p1068mcpsimp"><a name="p1068mcpsimp"></a><a name="p1068mcpsimp"></a>An existing file</p>
</td>
</tr>
</tbody>
</table>
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| pathname | Specifies the file path. | An existing file |
## Usage<a name="section186772414131"></a>
Run the **cat** \[_pathname_\] command to display the content of a text file.
## Usage Guidelines
## Example<a name="section12158131814561"></a>
Run the **cat** [*pathname*] command to display the content of a text file.
Run **cat hello-harmony.txt**.
## Output<a name="section183926225561"></a>
## Example
Content of **hello-harmony.txt**
Run **cat hello-openharmony.txt**.
## Output
Content of **hello-openharmony.txt**
```
OHOS # cat hello-harmony.txt
OHOS # Hello Harmony ;)
OHOS # cat hello-openharmony.txt
OHOS # Hello openharmony ;)
```
# cd
## Command Function<a name="section11690184921316"></a>
## Command Function
This command is used to change the current working directory.
## Syntax<a name="section75695409569"></a>
cd \[_path_\]
## Syntax
## Parameters<a name="section71961353181311"></a>
cd [_path_]
**Table 1** Parameter description
<a name="table1087mcpsimp"></a>
<table><thead align="left"><tr id="row1093mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p1095mcpsimp"><a name="p1095mcpsimp"></a><a name="p1095mcpsimp"></a><strong id="b76096875111729"><a name="b76096875111729"></a><a name="b76096875111729"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p1097mcpsimp"><a name="p1097mcpsimp"></a><a name="p1097mcpsimp"></a><strong id="b1343743615221"><a name="b1343743615221"></a><a name="b1343743615221"></a>Description</strong></p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p1099mcpsimp"><a name="p1099mcpsimp"></a><a name="p1099mcpsimp"></a><strong id="b163024311311729"><a name="b163024311311729"></a><a name="b163024311311729"></a>Value Range</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1100mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p1102mcpsimp"><a name="p1102mcpsimp"></a><a name="p1102mcpsimp"></a>path</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p1104mcpsimp"><a name="p1104mcpsimp"></a><a name="p1104mcpsimp"></a>Specifies the target file path.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p1106mcpsimp"><a name="p1106mcpsimp"></a><a name="p1106mcpsimp"></a>You must have the execution (search) permission for the specified directory.</p>
</td>
</tr>
</tbody>
</table>
## Parameters
## Usage<a name="section3629759111317"></a>
**Table 1** Parameter description
- If **path** is not specified, this command switches to the root directory.
- If **path** is specified, this command switches to the specified directory.
- The **path** value starting with a slash \(/\) represents the root directory.
- The **path** value starting with a dot \(.\) represents the current directory.
- The **path** value starting with two dots \(..\) represents the parent directory.
- You can run **cd -** to alternate between two directories that are recently accessed.
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| path | Specifies the path of the new directory. | You must have the execution (search) permission on the specified directory.|
## Example<a name="section211620301412"></a>
Run **cd ..**.
## Usage Guidelines
## Output<a name="section1968117214577"></a>
- If **path** is not specified, this command switches to the root directory.
- If **path** is specified, this command switches to the specified directory.
- The **path** value starting with a slash (/) represents the root directory.
- The **path** value starting with a dot (.) represents the current directory.
- The **path** value starting with two dots (..) represents the parent directory.
- You can run **cd -** to alternate between two directories that are recently accessed.
## Example
Run **cd ..**.
## Output
Parent directory information:
......@@ -55,4 +50,3 @@ OHOS:/$ ls
bin etc nfs sdcard system tmp vendor
dev lib proc storage test usr
```
# chgrp
## Command Function<a name="section6103119161418"></a>
## Command Function
This command is used to change the file group.
## Syntax<a name="section186958132141"></a>
chgrp \[_group_\] \[_pathname_\]
## Syntax
chgrp [_group_] [_pathname_]
## Parameters
## Parameters<a name="section81796174141"></a>
**Table 1** Parameter description
**Table 1** Parameter description
| Parameter | Description | Value Range |
| -------- | ---------- | -------------- |
| group | Specifies the target file group.| [0, 0xFFFFFFFF] |
| pathname | Specifies the file path. | An existing file |
<a name="table1049mcpsimp"></a>
<table><thead align="left"><tr id="row1055mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p1057mcpsimp"><a name="p1057mcpsimp"></a><a name="p1057mcpsimp"></a><strong id="b152503343511626"><a name="b152503343511626"></a><a name="b152503343511626"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p1059mcpsimp"><a name="p1059mcpsimp"></a><a name="p1059mcpsimp"></a><strong id="b14728419275"><a name="b14728419275"></a><a name="b14728419275"></a>Description</strong></p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p1061mcpsimp"><a name="p1061mcpsimp"></a><a name="p1061mcpsimp"></a><strong id="b71533702411626"><a name="b71533702411626"></a><a name="b71533702411626"></a>Value Range</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1062mcpsimp"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p1064mcpsimp"><a name="p1064mcpsimp"></a><a name="p1064mcpsimp"></a>group</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p1066mcpsimp"><a name="p1066mcpsimp"></a><a name="p1066mcpsimp"></a>Specifies the target file group.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p1068mcpsimp"><a name="p1068mcpsimp"></a><a name="p1068mcpsimp"></a>[0, 0xFFFFFFFF]</p>
</td>
</tr>
<tr id="row172161126124218"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p12217026154215"><a name="p12217026154215"></a><a name="p12217026154215"></a>pathname</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p4218826194210"><a name="p4218826194210"></a><a name="p4218826194210"></a>Specifies the file path.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p182181026104214"><a name="p182181026104214"></a><a name="p182181026104214"></a>An existing file</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section14330152417140"></a>
## Usage Guidelines
- Specify **group** to change the file group.
- For the FAT file system, this command cannot be used to change user group IDs.
- Specify **group** to change the file group.
- For the FAT file system, this command cannot be used to change user group IDs.
## Example<a name="section951823119149"></a>
## Note
Run **chgrp 100 testfile**.
Currently, the shell does not support this command.
## Output<a name="section14271133125715"></a>
## Example
Changing the group ID of the **testfile** file in the **dev/** directory to **100**
Run **chgrp 100 testfile**.
## Output
Change the group ID of the **testfile** file in the **dev/** directory to **100**.
```
OHOS:/dev$ ll testfile
......@@ -59,4 +47,3 @@ OHOS:/dev$ ll testfile
-rw-r--r-- 0 0 100 0 1970-01-01 00:00 testfile
OHOS:/dev$
```
# chmod
## Command Function<a name="section13992936121418"></a>
## Command Function
This command is used to change file operation permissions.
## Syntax<a name="section63342439147"></a>
chmod \[_mode_\] \[_filename_\]
## Syntax
chmod [_mode_] [_filename_]
## Parameters
**Table 1** Parameter description
## Parameter Description<a name="section894414671411"></a>
| Parameter | Description | Value Range |
| -------- | ------------------------------------------------------------ | -------------- |
| mode | Specifies the permissions for a file or directory. The value is an octal number, representing the permission of **User** (owner), **Group** (group), or **Others** (other groups).| [0, 777] |
| filename | Specifies the file path. | An existing file |
**Table 1** Parameters
<a name="table1049mcpsimp"></a>
<table><thead align="left"><tr id="row1055mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p1057mcpsimp"><a name="p1057mcpsimp"></a><a name="p1057mcpsimp"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p1059mcpsimp"><a name="p1059mcpsimp"></a><a name="p1059mcpsimp"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p1061mcpsimp"><a name="p1061mcpsimp"></a><a name="p1061mcpsimp"></a>Value Range</p>
</th>
</tr>
</thead>
<tbody><tr id="row2981144101719"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p20916441173"><a name="p20916441173"></a><a name="p20916441173"></a>mode</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p3911344161713"><a name="p3911344161713"></a><a name="p3911344161713"></a>Specifies the permissions for a file or directory. The value is an octal number, representing the permission of <strong id="b11602834153114"><a name="b11602834153114"></a><a name="b11602834153114"></a>User</strong> (owner), <strong id="b032113853120"><a name="b032113853120"></a><a name="b032113853120"></a>Group</strong> (group), or <strong id="b1980114418310"><a name="b1980114418310"></a><a name="b1980114418310"></a>Others</strong> (other groups).</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p1591744161719"><a name="p1591744161719"></a><a name="p1591744161719"></a>[0,777]</p>
</td>
</tr>
<tr id="row15985440173"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p99124461717"><a name="p99124461717"></a><a name="p99124461717"></a>filename</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p149134481719"><a name="p149134481719"></a><a name="p149134481719"></a>Specifies the file name.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p0911144181712"><a name="p0911144181712"></a><a name="p0911144181712"></a>An existing file</p>
</td>
</tr>
</tbody>
</table>
## Usage Guidelines
## Usage<a name="section182415221419"></a>
- Specify **mode** to change file permissions.
- Specify **mode** to change file permissions.
- For the files created on the FAT file system, the file permission attributes are the same as those of the mounted nodes. Currently, the node permissions include only user read and write. The **group** and **others** permissions do not take effect. In addition, only the user read and write permissions can be modified. The read and write permissions are **rw** and **ro** only. There is no such restriction for other file systems.
- For the files created on the FAT file system, the file permission attributes are the same as those of the mounted nodes. Currently, the node permissions include only user read and write. The **group** and **others** permissions do not take effect. In addition, only the user read and write permissions can be modified. The read and write permissions are **rw** and **ro** only. There is no such restriction for other file systems.
## Example<a name="section8518195718147"></a>
## Note
Change the permissions on the **hello-harmony.txt** file to **644** and **777**.
Currently, the shell does not support this command.
## Output<a name="section127391818158"></a>
## Example
Modifying the permissions on the **hello-harmony.txt** file in the **/dev** directory:
Change the permissions on the **hello-openharmony.txt** file to **644** and **777**.
## Output
Modify the permissions on the **hello-openharmony.txt** file in the **/dev** directory.
```
OHOS:/dev$ chmod 644 hello-harmony.txt
OHOS:/dev$ ll hello-harmony.txt
-rw-r--r-- 0 0 0 0 1970-01-01 00:00 hello-harmony.txt
OHOS:/dev$ chmod 777 hello-harmony.txt
OHOS:/dev$ ll hello-harmony.txt
-rwxrwxrwx 0 0 0 0 1970-01-01 00:00 hello-harmony.txt
OHOS:/dev$ chmod 644 hello-openharmony.txt
OHOS:/dev$ ll hello-openharmony.txt
-rw-r--r-- 0 0 0 0 1970-01-01 00:00 hello-openharmony.txt
OHOS:/dev$ chmod 777 hello-openharmony.txt
OHOS:/dev$ ll hello-openharmony.txt
-rwxrwxrwx 0 0 0 0 1970-01-01 00:00 hello-openharmony.txt
```
# chown
## Command Function<a name="section247414691513"></a>
## Command Function
This command is used to change the owner of a file.
## Syntax<a name="section14773151018159"></a>
chown \[_owner_\] \[_pathname_\]
## Parameters<a name="section598731391517"></a>
**Table 1** Parameter description
<a name="table1049mcpsimp"></a>
<table><thead align="left"><tr id="row1055mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p1057mcpsimp"><a name="p1057mcpsimp"></a><a name="p1057mcpsimp"></a><strong id="b130925344111510"><a name="b130925344111510"></a><a name="b130925344111510"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p1059mcpsimp"><a name="p1059mcpsimp"></a><a name="p1059mcpsimp"></a><strong id="b1226032904716"><a name="b1226032904716"></a><a name="b1226032904716"></a>Description</strong></p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p1061mcpsimp"><a name="p1061mcpsimp"></a><a name="p1061mcpsimp"></a><strong id="b34190246311510"><a name="b34190246311510"></a><a name="b34190246311510"></a>Value Range</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1541931122113"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p84121716217"><a name="p84121716217"></a><a name="p84121716217"></a>owner</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p14126172111"><a name="p14126172111"></a><a name="p14126172111"></a>Specifies the file owner.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p24129113218"><a name="p24129113218"></a><a name="p24129113218"></a>[0,0xFFFFFFFF]</p>
</td>
</tr>
<tr id="row12419191192111"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p141215115212"><a name="p141215115212"></a><a name="p141215115212"></a>pathname</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p7412315218"><a name="p7412315218"></a><a name="p7412315218"></a>Specifies the file path.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p134126102118"><a name="p134126102118"></a><a name="p134126102118"></a>An existing file</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section16524152071510"></a>
## Syntax
chown [_owner_] [_pathname_]
## Parameters
**Table 1** Parameter description
| Parameter | Description | Value Range |
| -------- | ------------ | -------------- |
| owner | Specifies the file owner. | [0, 0xFFFFFFFF] |
| pathname | Specifies the file path. | An existing file |
## Usage Guidelines
This command does not apply to the FAT file system.
## Example<a name="section17901152561510"></a>
## Note
Currently, the shell does not support this command.
Run **chown 100 testfile**.
## Example
## Output<a name="section15513163115816"></a>
Run **chown 100 testfile**.
Changing the UID of the **testfile** file in **/dev** to **100**:
## Output
Change the UID of the **testfile** file in **/dev** to **100**.
```
OHOS:/dev$ touch testfile
......@@ -58,4 +46,3 @@ OHOS:/dev$ chown 100 testfile
OHOS:/dev$ ll testfile
-rw-r--r-- 0 100 100 0 1970-01-01 00:00 testfile
```
# cp
## Command Function<a name="section6841203041513"></a>
## Command Function
This command is used to create a copy for a file.
## Syntax<a name="section24286359150"></a>
cp \[_SOURCEFILE_\] \[_DESTFILE_\]
## Parameters<a name="section558617385152"></a>
**Table 1** Parameter description
<a name="table1130mcpsimp"></a>
<table><thead align="left"><tr id="row1136mcpsimp"><th class="cellrowborder" valign="top" width="21%" id="mcps1.2.4.1.1"><p id="p1138mcpsimp"><a name="p1138mcpsimp"></a><a name="p1138mcpsimp"></a><strong id="b203611832412"><a name="b203611832412"></a><a name="b203611832412"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="52%" id="mcps1.2.4.1.2"><p id="p1140mcpsimp"><a name="p1140mcpsimp"></a><a name="p1140mcpsimp"></a><strong id="b1170512342014"><a name="b1170512342014"></a><a name="b1170512342014"></a>Description</strong></p>
</th>
<th class="cellrowborder" valign="top" width="27%" id="mcps1.2.4.1.3"><p id="p1142mcpsimp"><a name="p1142mcpsimp"></a><a name="p1142mcpsimp"></a><strong id="b173835351418"><a name="b173835351418"></a><a name="b173835351418"></a>Value Range</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row217620816236"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p181687832310"><a name="p181687832310"></a><a name="p181687832310"></a>--help</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p181687882317"><a name="p181687882317"></a><a name="p181687882317"></a>Displays help information.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p18168118182312"><a name="p18168118182312"></a><a name="p18168118182312"></a>N/A</p>
</td>
</tr>
<tr id="row1417648122313"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p516816822316"><a name="p516816822316"></a><a name="p516816822316"></a>SOURCEFILE</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p81686862314"><a name="p81686862314"></a><a name="p81686862314"></a>Specifies the path of the source file.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p1016811862312"><a name="p1016811862312"></a><a name="p1016811862312"></a>This command does not support copy of a directory, but supports copy of multiple files at a time.</p>
</td>
</tr>
<tr id="row191761384231"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.2.4.1.1 "><p id="p13168880235"><a name="p13168880235"></a><a name="p13168880235"></a>DESTFILE</p>
</td>
<td class="cellrowborder" valign="top" width="52%" headers="mcps1.2.4.1.2 "><p id="p9168789231"><a name="p9168789231"></a><a name="p9168789231"></a>Specifies the destination file path.</p>
</td>
<td class="cellrowborder" valign="top" width="27%" headers="mcps1.2.4.1.3 "><p id="p316810810235"><a name="p316810810235"></a><a name="p316810810235"></a>Both a directory and a file are supported.</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section16128156162"></a>
- The name of the source file cannot be the same as that of the destination file in the same path.
- **SOURCEFILE** must exist and cannot be a directory.
- **SOURCEFILE** supports wildcard characters \* and ?. The asterisk \(\*\) indicates any number of characters, and the question mark \(?\) represents a single character. **DESTFILE** does not support wildcard characters. If **SOURCEFILE** specifies multiple files, **DESTFILE** must be a directory.
- If **DESTFILE** specifies a directory, this directory must exist. In this case, the destination file is named after the source file.
- If **DESTFILE** specifies a file, the directory for this file must exist. In this case, the file copy is renamed.
- If the destination file does not exist, a new file is created. If the destination file already exists, the existing file is overwritten.
>![](../public_sys-resources/icon-notice.gif) **NOTICE:**
>When important system resources are copied, unexpected results such as a system breakdown may occur. For example, when the **/dev/uartdev-1** file is copied, the system may stop responding.
## Example<a name="section19354171211618"></a>
Run **cp hello-OHOS.txt hello-harmony.txt ./tmp/**.
## Output<a name="section16754183195914"></a>
Copying **hello-OHOS.txt** and **hello-harmony.txt** to **/tmp/**:
## Syntax
cp [_SOURCEFILE_] [_DESTFILE_]
## Parameters
**Table 1** Parameter description
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| --help | Displays help information.| N/A |
| SOURCEFILE | Specifies the file to copy.| This command does not support copy of a directory, but supports copy of multiple files at a time.|
| DESTFILE | Specifies the file to create.| Both a directory and a file are supported.|
## Usage Guidelines
- The name of the source file cannot be the same as that of the destination file in the same path.
- **SOURCEFILE** must exist and cannot be a directory.
- The source file path supports asterisks (*) and question marks (?). The wildcard "\*" indicates any number of characters, and "?" indicates any single character. **DEST** does not support wildcard characters. If the specified **SOURCE** matches multiple files, **DEST** must be a directory.
- If **DEST** is a directory, this directory must exist. In this case, the destination file is named after the source file.
- If the destination file path is a file, the directory for this file must exist. In this case, the file copy is renamed.
- If the destination file does not exist, a new file is created. If the destination file already exists, the existing file is overwritten.
> **NOTICE**<br>
> When important system resources are copied, unexpected results such as a system breakdown may occur. For example, when the **/dev/uartdev-1** file is copied, the system may stop responding.
## Example
Run **cp hello-OHOS.txt hello-openharmony.txt ./tmp/**.
## Output
Copy **hello-OHOS.txt** and **hello-openharmony.txt** to **/tmp/**.
```
OHOS:/$ ls
bin hello-OHOS.txt proc system vendor
dev hello-harmony.txt sdcard userdata
dev hello-openharmony.txt sdcard userdata
etc lib storage usr
OHOS:/$ mkdir tmp
OHOS:/$ cp hello-OHOS.txt hello-harmony.txt tmp/
OHOS:/$ cp hello-OHOS.txt hello-openharmony.txt tmp/
OHOS:/$ ll tmp
total 0
-rwxrwxrwx 1 0 0 0 1979-12-31 00:00 hello-OHOS.txt*
-rwxrwxrwx 1 0 0 0 1979-12-31 00:00 hello-harmony.txt*
-rwxrwxrwx 1 0 0 0 1979-12-31 00:00 hello-openharmony.txt*
```
# format
## Command Function<a name="section1922331919169"></a>
## Command Function
This command is used for disk formatting.
## Syntax<a name="section249226169"></a>
format <_dev\_inodename_\> <_sectors_\> <_option_\> \[_label_\]
## Parameters<a name="section985173416177"></a>
**Table 1** Parameter description
<a name="table1183mcpsimp"></a>
<table><thead align="left"><tr id="row1188mcpsimp"><th class="cellrowborder" valign="top" width="34%" id="mcps1.2.3.1.1"><p id="p1190mcpsimp"><a name="p1190mcpsimp"></a><a name="p1190mcpsimp"></a><strong id="b101095916104"><a name="b101095916104"></a><a name="b101095916104"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="66%" id="mcps1.2.3.1.2"><p id="p1192mcpsimp"><a name="p1192mcpsimp"></a><a name="p1192mcpsimp"></a><strong id="b14213111171020"><a name="b14213111171020"></a><a name="b14213111171020"></a>Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1193mcpsimp"><td class="cellrowborder" valign="top" width="34%" headers="mcps1.2.3.1.1 "><p id="p1195mcpsimp"><a name="p1195mcpsimp"></a><a name="p1195mcpsimp"></a>dev_inodename</p>
</td>
<td class="cellrowborder" valign="top" width="66%" headers="mcps1.2.3.1.2 "><p id="p1197mcpsimp"><a name="p1197mcpsimp"></a><a name="p1197mcpsimp"></a>Specifies the device name.</p>
</td>
</tr>
<tr id="row1203mcpsimp"><td class="cellrowborder" valign="top" width="34%" headers="mcps1.2.3.1.1 "><p id="p1205mcpsimp"><a name="p1205mcpsimp"></a><a name="p1205mcpsimp"></a>sectors</p>
</td>
<td class="cellrowborder" valign="top" width="66%" headers="mcps1.2.3.1.2 "><p id="p1207mcpsimp"><a name="p1207mcpsimp"></a><a name="p1207mcpsimp"></a>Specifies the size of the allocated memory unit or sector. The value <strong id="b1574273871018"><a name="b1574273871018"></a><a name="b1574273871018"></a>0</strong> indicates null. (The value must be <strong id="b16428721113"><a name="b16428721113"></a><a name="b16428721113"></a>0</strong> or a power of <strong id="b1053419931111"><a name="b1053419931111"></a><a name="b1053419931111"></a>2</strong>. For FAT32, the maximum value is <strong id="b51473841110"><a name="b51473841110"></a><a name="b51473841110"></a>128</strong>. If the parameter is set to <strong id="b99547931214"><a name="b99547931214"></a><a name="b99547931214"></a>0</strong>, a proper cluster size is automatically selected. The available cluster size range varies depending on the partition size. If the cluster size is incorrectly specified, the formatting may fail.)</p>
</td>
</tr>
<tr id="row1208mcpsimp"><td class="cellrowborder" valign="top" width="34%" headers="mcps1.2.3.1.1 "><p id="p1210mcpsimp"><a name="p1210mcpsimp"></a><a name="p1210mcpsimp"></a>option</p>
</td>
<td class="cellrowborder" valign="top" width="66%" headers="mcps1.2.3.1.2 "><div class="p" id="p1212mcpsimp"><a name="p1212mcpsimp"></a><a name="p1212mcpsimp"></a>Specifies the file system type. The options are as follows:<a name="ul10971366369"></a><a name="ul10971366369"></a><ul id="ul10971366369"><li><strong id="b169384514517"><a name="b169384514517"></a><a name="b169384514517"></a>0x01</strong>: FMT_FAT</li><li><strong id="b143061510125114"><a name="b143061510125114"></a><a name="b143061510125114"></a>0x02</strong>: FMT_FAT32</li><li><strong id="b3245614165116"><a name="b3245614165116"></a><a name="b3245614165116"></a>0x07</strong>: FMT_ANY</li><li><strong id="b018121813512"><a name="b018121813512"></a><a name="b018121813512"></a>0x08</strong>: FMT_ERASE (not supported by the USB flash drive)</li></ul>
</div>
<p id="p28366459374"><a name="p28366459374"></a><a name="p28366459374"></a>If an invalid value is specified, the system automatically selects the formatting mode. If the low-level formatting bit is <strong id="b4634562520"><a name="b4634562520"></a><a name="b4634562520"></a>1</strong> during the formatting of a USB flash drive, an error message is printed.</p>
</td>
</tr>
<tr id="row1213mcpsimp"><td class="cellrowborder" valign="top" width="34%" headers="mcps1.2.3.1.1 "><p id="p1215mcpsimp"><a name="p1215mcpsimp"></a><a name="p1215mcpsimp"></a>label</p>
</td>
<td class="cellrowborder" valign="top" width="66%" headers="mcps1.2.3.1.2 "><p id="p1217mcpsimp"><a name="p1217mcpsimp"></a><a name="p1217mcpsimp"></a>Specifies the volume label name. This parameter is optional, and the value is a string. If <strong id="b16648426102713"><a name="b16648426102713"></a><a name="b16648426102713"></a>null</strong> is specified for this parameter, the previously set volume label name is cleared.</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section1510162714162"></a>
- The **format** command is used for disk formatting. You can find the device name in the **dev** directory. A storage card must be installed before the formatting.
- The **format** command can be used to format the USB flash drive, SD card, and MMC, but not the NAND flash or NOR flash.
- An invalid **sectors** value may cause exceptions.
## Example<a name="section25691431161611"></a>
Run **format /dev/mmcblk0 128 2**.
## Output<a name="section17368112365920"></a>
Formatting an MMC:
## Syntax
format &lt;*dev*inodename_&gt; &lt;*sectors*&gt; &lt;*option*&gt; [_label_]
## Parameters
**Table 1** Parameter description
| Parameter| Description|
| -------- | -------- |
| dev_inodename | Specifies the device name. |
| sectors | Specifies the size of the allocated memory unit or sector. <br/>The value must be **0** or a power of **2**.<br/>The value **0** means to leave this parameter blank. <br/>For FAT32, the maximum value is **128**. If the parameter is set to **0**, a proper cluster size is automatically selected. The available cluster size range varies depending on the partition size. If the cluster size is incorrectly specified, the formatting may fail. |
| option | Specifies the file system type. The options are as follows:<br>- **0x01**: FMT_FAT<br>- **0x02**: FMT_FAT32<br>- **0x07**: FMT_ANY<br>- **0x08**: FMT_ERASE (USB does not support this option.)<br>If an invalid value is specified, the system automatically selects the formatting mode. If the low-level formatting bit is **1** during the formatting of a USB flash drive, an error message is printed.|
| label | Specifies the volume label name. This parameter is optional, and the value is a string. <br/>If **null** is specified for this parameter, the previously set volume label name is cleared. |
## Usage Guidelines
- The **format** command is used for disk formatting. You can find the device name in the **dev** directory. A storage card must be installed before the formatting.
- The **format** command can be used to format the USB flash drive, SD card, and MMC, but not the NAND flash or NOR flash.
- An invalid **sectors** value may cause exceptions.
## Example
Run **format /dev/mmcblk0 128 2**.
## Output
Format an MMC.
```
OHOS # format /dev/mmcblk1 128 2
Format to FAT32, 128 sectors per cluster.
format /dev/mmcblk1 Success
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册