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.
## Working Principles
- 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:
OpenHarmony has encapsulated the **LDREX** and **STREX** in the ARMv6 architecture to provide a set of atomic operation APIs.
- 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:
- LDREX Rx, [Ry]
- The memory is not updated.
Reads the value in the memory and marks the exclusive access to the memory segment.
- The system sets the **Rf** register to **1**.
- 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
- Flag register
- If the flag register is **0**, the system exits the loop and the atomic operation is complete.
- 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.
- If the flag register is**1**, the system continues the loop and performs the atomic operation again.
## Development Guidelines
## Development Guidelines
### Available APIs
### 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.
The following table describes the APIs available for the OpenHarmony LiteOS-A kernel atomic operation module.
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p59414511172"><aname="p59414511172"></a><aname="p59414511172"></a>Adds 1 to 32-bit atomic data and returns the data.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1194951111713"><aname="p1194951111713"></a><aname="p1194951111713"></a>Adds 1 to 64-bit atomic data and returns the data.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p198222414349"><aname="p198222414349"></a><aname="p198222414349"></a>Subtracts 1 from 32-bit atomic data and returns the result.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p198221841103419"><aname="p198221841103419"></a><aname="p198221841103419"></a>Subtracts 1 from 64-bit atomic data and returns the result.</p>
<trid="row149616511175"><tdclass="cellrowborder"rowspan="4"valign="top"width="21.21212121212121%"headers="mcps1.2.4.1.1 "><pid="p49615120172"><aname="p49615120172"></a><aname="p49615120172"></a>Compare and swap</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1296205118179"><aname="p1296205118179"></a><aname="p1296205118179"></a>Compares and swaps 64-bit memory data.</p>
</td>
</tr>
</tbody>
</table>
### How to Develop
### 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.
When multiple tasks perform addition, subtraction, and swap operations on the same memory data, use atomic operations to ensure predictability of results.
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:
The software timer supports the following functions:
- Disabling the software timer using a macro
- 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
## 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.
- 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.
- Periodic timer: This type of timer periodically triggers timer events until it is manually stopped.
- One-shot timer deleted by calling an API
- One-shot timer deleted by calling an API
## Development Guidelines<a name="section18576131520577"></a>
## Development Guidelines
### 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.
### Available APIs
**Table 1** Software timer APIs
The following table describes the APIs of the software timer module of the OpenHarmony LiteOS-A kernel.
| Starting or stopping a timer | **LOS_SwtmrStart**: starts a software timer.<br>**LOS_SwtmrStop**: stops a software timer.|
</th>
| Obtaining remaining ticks of a software timer| **LOS_SwtmrTimeGet**: obtains the remaining ticks of a software timer. |
</tr>
</thead>
<tbody><trid="row1470413222429"><tdclass="cellrowborder"rowspan="2"valign="top"width="20.6020602060206%"headers="mcps1.2.4.1.1 "><pid="p8284115918428"><aname="p8284115918428"></a><aname="p8284115918428"></a>Creating or deleting timers</p>
<tdclass="cellrowborder"valign="top"width="49.85498549854985%"headers="mcps1.2.4.1.3 "><pid="p170422234213"><aname="p170422234213"></a><aname="p170422234213"></a>Creates a software timer.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p870442211421"><aname="p870442211421"></a><aname="p870442211421"></a>Deletes a software timer.</p>
</td>
</tr>
<trid="row57041422184215"><tdclass="cellrowborder"rowspan="2"valign="top"width="20.6020602060206%"headers="mcps1.2.4.1.1 "><pid="p1476172124318"><aname="p1476172124318"></a><aname="p1476172124318"></a>Starting or stopping timers</p>
<tdclass="cellrowborder"valign="top"width="49.85498549854985%"headers="mcps1.2.4.1.3 "><pid="p1570412229421"><aname="p1570412229421"></a><aname="p1570412229421"></a>Starts a software timer.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p17705122211426"><aname="p17705122211426"></a><aname="p17705122211426"></a>Stops a software timer.</p>
</td>
</tr>
<trid="row12705222154214"><tdclass="cellrowborder"valign="top"width="20.6020602060206%"headers="mcps1.2.4.1.1 "><pid="p0705622134214"><aname="p0705622134214"></a><aname="p0705622134214"></a>Obtaining remaining ticks of a software timer</p>
<tdclass="cellrowborder"valign="top"width="49.85498549854985%"headers="mcps1.2.4.1.3 "><pid="p3705122264210"><aname="p3705122264210"></a><aname="p3705122264210"></a>Obtains the number of remaining ticks of a software timer.</p>
</td>
</tr>
</tbody>
</table>
### How to Develop<a name="section1344817403575"></a>
The typical development process of software timers is as follows:
The typical development process of software timers is as follows:
1. Configure the software timer.
1. Configure the software timer.
- Check that **LOSCFG\_BASE\_CORE\_SWTMR** and **LOSCFG\_BASE\_IPC\_QUEUE** are enabled.
- 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 **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\).
- 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.
4. Call **LOS_SwtmrTimeGet** to obtain the remaining number of ticks of the 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.
5. Call **LOS_SwtmrStop** to stop 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.
6. Call **LOS_SwtmrDelete** to delete the software timer.
>- 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.
### 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.
### Development Example
- 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.
**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**
**Sample Code**
...
@@ -164,14 +150,14 @@ void Timer_example(void)
...
@@ -164,14 +150,14 @@ void Timer_example(void)
UINT16 id2; // timer id
UINT16 id2; // timer id
UINT32 uwTick;
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. */
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.
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.
<tdclass="cellrowborder"valign="top"width="33.33333333333333%"headers="mcps1.2.4.1.3 "><pid="p8504121996"><aname="p8504121996"></a><aname="p8504121996"></a>Converts milliseconds into ticks.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p161632181721"><aname="p161632181721"></a><aname="p161632181721"></a>Converts ticks into milliseconds.</p>
<tdclass="cellrowborder"valign="top"width="33.33333333333333%"headers="mcps1.2.4.1.3 "><pid="p615864811116"><aname="p615864811116"></a><aname="p615864811116"></a>Obtains the current number of ticks.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p151631718124"><aname="p151631718124"></a><aname="p151631718124"></a>Obtains the number of cycles per tick.</p>
</td>
</tr>
</tbody>
</table>
### How to Develop
### How to Develop
1. Call APIs to convert time.
1. Call APIs to convert time.
2. Call APIs to perform time statistics.
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.
>- 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
### Development Example
**Prerequisites**<br>
**Prerequisites**
The following parameters are configured:
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].
-**LOSCFG_BASE_CORE_TICK_PER_SECOND**: number of ticks/second. The value range is (0, 1000).
@@ -9,29 +9,25 @@ A mutex has three attributes: protocol attribute, priority upper limit attribute
...
@@ -9,29 +9,25 @@ A mutex has three attributes: protocol attribute, priority upper limit attribute
- LOS_MUX_PRIO_NONE
- 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
- 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
- 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.
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
- 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
- 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
- LOS_MUX_ERRORCHECK
...
@@ -44,7 +40,7 @@ In a multi-task environment, multiple tasks may access the same shared resources
...
@@ -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.
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
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 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.
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.
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.
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.
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.
<tbody><trid="row04981218910"><tdclass="cellrowborder"valign="top"width="27.09270927092709%"headers="mcps1.2.4.1.1 "><pid="p6462616696"><aname="p6462616696"></a><aname="p6462616696"></a>Putting a thread to wait</p>
<tdclass="cellrowborder"valign="top"width="46.384638463846386%"headers="mcps1.2.4.1.3 "><pid="p8504121996"><aname="p8504121996"></a><aname="p8504121996"></a>Inserts a node representing a blocked thread into the futex list.</p>
</td>
</tr>
<trid="row7162101814216"><tdclass="cellrowborder"valign="top"width="27.09270927092709%"headers="mcps1.2.4.1.1 "><pid="p37331032985"><aname="p37331032985"></a><aname="p37331032985"></a>Waking up a thread</p>
<tdclass="cellrowborder"valign="top"width="46.384638463846386%"headers="mcps1.2.4.1.3 "><pid="p161632181721"><aname="p161632181721"></a><aname="p161632181721"></a>Wakes up a thread that is blocked by a specified lock.</p>
</td>
</tr>
<trid="row101631818620"><tdclass="cellrowborder"valign="top"width="27.09270927092709%"headers="mcps1.2.4.1.1 "><pid="p146111936887"><aname="p146111936887"></a><aname="p146111936887"></a>Modifying the lock address</p>
<tdclass="cellrowborder"valign="top"width="46.384638463846386%"headers="mcps1.2.4.1.3 "><pid="p151631718124"><aname="p151631718124"></a><aname="p151631718124"></a>Adjusts the position of a specified lock in the futex list.</p>
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.
<tbody><trid="row04981218910"><tdclass="cellrowborder"rowspan="2"valign="top"width="27.09270927092709%"headers="mcps1.2.4.1.1 "><pid="p6462616696"><aname="p6462616696"></a><aname="p6462616696"></a>Registering the signal callback</p>
<tdclass="cellrowborder"valign="top"width="46.41464146414641%"headers="mcps1.2.4.1.3 "><pid="p8504121996"><aname="p8504121996"></a><aname="p8504121996"></a>Registers the main signal entry, and registers and unregisters the callback function of a signal.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1945083962113"><aname="p1945083962113"></a><aname="p1945083962113"></a>Same as <strongid="b1076755712371"><aname="b1076755712371"></a><aname="b1076755712371"></a>signal</strong>. This API is added with configuration options related to signal transmission. Currently, only some parameters in the <strongid="b18458105019218"><aname="b18458105019218"></a><aname="b18458105019218"></a>SIGINFO</strong> structure are supported.</p>
<tdclass="cellrowborder"rowspan="5"align="left"valign="top"width="46.41464146414641%"headers="mcps1.2.4.1.3 "><pid="p161632181721"><aname="p161632181721"></a><aname="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>
<trid="row101631818620"><tdclass="cellrowborder"valign="top"width="27.09270927092709%"headers="mcps1.2.4.1.1 "><pid="p146111936887"><aname="p146111936887"></a><aname="p146111936887"></a>Triggering a callback</p>
<tdclass="cellrowborder"valign="top"width="46.41464146414641%"headers="mcps1.2.4.1.3 "><pid="p1126941694213"><aname="p1126941694213"></a><aname="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>
| 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.|
>void *signal(int sig, void (*func)(int))(int);
| 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.|
>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.
>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.
> **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 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\)
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p48623102592"><aname="p48623102592"></a><aname="p48623102592"></a>Initializes the LiteIPC module.</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p1886211011599"><aname="p1886211011599"></a><aname="p1886211011599"></a>Initializes the IPC message memory pool of processes.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p586261085913"><aname="p586261085913"></a><aname="p586261085913"></a>Re-initializes the IPC message memory pool of processes.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p555221518598"><aname="p555221518598"></a><aname="p555221518598"></a>Releases the IPC message memory pool of processes.</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p1555261595915"><aname="p1555261595915"></a><aname="p1555261595915"></a>Deletes the specified Service.</p>
>LiteIPC module APIs are used for LiteOS-A internal use only.
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)
| 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.
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.
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**
**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.
- 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.
- 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>
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\).
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 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.
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<aname="fig17879151310447"></a>
1. The loader and linker call **mmap** to map the **PT\_LOAD** section.
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.
2. The kernel calls **map_pages** to search for and map the existing PageCache.
4. Map the physical memory blocks of the file read to the virtual address region.
5. The program continues to run.
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.
## Development Guidelines<a name="section133501496612"></a>
4. Map the physical memory blocks of the file read to the virtual address region.
### Available APIs<a name="section874113201669"></a>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p48623102592"><aname="p48623102592"></a><aname="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.
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.
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:
VDSO can be divided into:
- Data page: provides the kernel-time data mapped to the user process.
- Data page: provides the kernel-time data mapped to the user process.
- Code page: provides the logic for shielding system calls.
- Code page: provides the logic for shielding system calls.
**Figure 1** VDSO system design
**Figure 1** VDSO system design<aname="fig1986131094711"></a>
>- 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.
> - 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.
<tdclass="cellrowborder"valign="top"width="56.99999999999999%"headers="mcps1.2.4.1.2 "><aname="ul1530071303413"></a><aname="ul1530071303413"></a><ulid="ul1530071303413"><li>Displays the CPU usage of the system within the last 10 seconds by default.</li><li><strongid="b13709113084810"><aname="b13709113084810"></a><aname="b13709113084810"></a>0</strong>: displays the CPU usage within the last 10 seconds.</li><li><strongid="b10788133319480"><aname="b10788133319480"></a><aname="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>
<tdclass="cellrowborder"valign="top"width="56.99999999999999%"headers="mcps1.2.4.1.2 "><pid="p3799mcpsimp"><aname="p3799mcpsimp"></a><aname="p3799mcpsimp"></a>Specifies the task ID.</p>
- If no parameter is specified, the CPU usage of the system within the last 10 seconds is displayed.
| Parameter| Description| Value Range|
- 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.
| 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.
| -u | Displays UTC (not the current time zone). | N/A |
</td>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.4.1.2 "><pid="p1162201234017"><aname="p1162201234017"></a><aname="p1162201234017"></a>Displays help information.</p>
- The **--help**, **+Format**, and **-u** parameters are mutually exclusive.
</td>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.4.1.2 "><pid="p26216124407"><aname="p26216124407"></a><aname="p26216124407"></a>Prints the date and time in the specified <strongid="b115041849185916"><aname="b115041849185916"></a><aname="b115041849185916"></a>Format</strong>.</p>
- Currently, this command cannot be used to set the time or date.
</td>
<tdclass="cellrowborder"valign="top"width="28.999999999999996%"headers="mcps1.2.4.1.3 "><pid="p46251220409"><aname="p46251220409"></a><aname="p46251220409"></a>Placeholders listed in <strongid="b36588246116"><aname="b36588246116"></a><aname="b36588246116"></a>--help</strong></p>
## Note
</td>
</tr>
The shell does not support **date -u**. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.4.1.2 "><pid="p136291219403"><aname="p136291219403"></a><aname="p136291219403"></a>Displays UTC instead of the current time zone.</p>
| > fileA | Writes the content in the buffer to a file. | N/A |
</td>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3917mcpsimp"><aname="p3917mcpsimp"></a><aname="p3917mcpsimp"></a>Prints content in the buffer and clears the buffer.</p>
- 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**.
</tr>
Debug ---> Enable a Debug Version ---> Enable Shell ---> Enable Shell dmesg
- If no parameter is specified, all content in the buffer is printed.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3924mcpsimp"><aname="p3924mcpsimp"></a><aname="p3924mcpsimp"></a>Clears the buffer.</p>
</td>
- The parameters followed by hyphens (-) are mutually exclusive.
1. Before writing content to a file, ensure that the file system has been mounted.
</td>
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.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3931mcpsimp"><aname="p3931mcpsimp"></a><aname="p3931mcpsimp"></a>Disables or enables printing to the console.</p>
Write the content in the buffer to the **dmesg.log** file.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3938mcpsimp"><aname="p3938mcpsimp"></a><aname="p3938mcpsimp"></a>Disables or enables printing via the serial port.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3945mcpsimp"><aname="p3945mcpsimp"></a><aname="p3945mcpsimp"></a>Sets the size of the buffer.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3952mcpsimp"><aname="p3952mcpsimp"></a><aname="p3952mcpsimp"></a>Sets the buffering level.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p717417317512"><aname="p717417317512"></a><aname="p717417317512"></a>Writes the content in the buffer to the specified file.</p>
- 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:
| 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.
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.
>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.
> 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.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p64861302212"><aname="p64861302212"></a><aname="p64861302212"></a>Displays the memory usage in bytes.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1648617012214"><aname="p1648617012214"></a><aname="p1648617012214"></a>Displays the parameters supported by the <strongid="b1247315411335"><aname="b1247315411335"></a><aname="b1247315411335"></a>free</strong> command.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p54864013214"><aname="p54864013214"></a><aname="p54864013214"></a>Displays the memory usage in bytes.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1648670192120"><aname="p1648670192120"></a><aname="p1648670192120"></a>Displays the memory usage in KiB.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p134869022114"><aname="p134869022114"></a><aname="p134869022114"></a>Displays the memory usage in MiB.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p348680122118"><aname="p348680122118"></a><aname="p348680122118"></a>Displays the memory usage in GiB.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p18486140132118"><aname="p18486140132118"></a><aname="p18486140132118"></a>Displays the memory usage in TiB.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1737315202218"><aname="p1737315202218"></a><aname="p1737315202218"></a>Total size of the dynamic memory pool</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p197376156222"><aname="p197376156222"></a><aname="p197376156222"></a>Size of the used memory</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p97371915142218"><aname="p97371915142218"></a><aname="p97371915142218"></a>Size of the unallocated memory</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1773801514223"><aname="p1773801514223"></a><aname="p1773801514223"></a>Size of the shared memory</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p157381015192216"><aname="p157381015192216"></a><aname="p157381015192216"></a>Size of the buffer</p>
<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 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 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>
| pid | Specifies the process ID. | [1, MAX_INT] |
</td>
<tdclass="cellrowborder"valign="top"width="51.92%"headers="mcps1.2.4.1.2 "><pid="p3402191493310"><aname="p3402191493310"></a><aname="p3402191493310"></a>Displays the parameters supported by the <strongid="b277973411569"><aname="b277973411569"></a><aname="b277973411569"></a>kill</strong> command.</p>
> **NOTICE**<br>
</td>
> The value range of **signo** is [0, 64]. The recommended value range is [1, 30], and other values in the value range are reserved.
- The **signo** and **pid** parameters are mandatory.
<tdclass="cellrowborder"valign="top"width="51.92%"headers="mcps1.2.4.1.2 "><pid="p640281413313"><aname="p640281413313"></a><aname="p640281413313"></a>Lists the names and numbers of signals.</p>
</td>
- 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].
<tdclass="cellrowborder"valign="top"width="51.92%"headers="mcps1.2.4.1.2 "><pid="p114023144336"><aname="p114023144336"></a><aname="p114023144336"></a>Specifies the signal number.</p>
PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName
<tdclass="cellrowborder"valign="top"width="51.92%"headers="mcps1.2.4.1.2 "><pid="p7402014113310"><aname="p7402014113310"></a><aname="p7402014113310"></a>Specifies the process ID.</p>
>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>
- 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.
- 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\].
OHOS:/$ kill -s 9 42
OHOS:/$
## Example<a name="section79281818476"></a>
[1] + Killed ./nfs/test_demo
OHOS:/$ ps
- Query the process list before killing process 42.
allCpu(%): 4.73 sys, 195.27 idle
PID PPID PGID UID Status VirtualMem ShareMem PhysicalMem CPUUSE10s PName
- 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.
The command output is as follows:
```
OHOS:/$ kill -s 9 42
Example 1: The signal is successfully sent to process 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
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p254mcpsimp"><aname="p254mcpsimp"></a><aname="p254mcpsimp"></a>Specifies the level of logs to print.</p>
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.
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
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
OHOS # memcheck
system memcheck over, all passed!
system memcheck over, all passed!
```
```
Example 2: Out-of-bounds memory access is detected.
| -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. |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1149945111817"><aname="p1149945111817"></a><aname="p1149945111817"></a>Sets the interval (in ms) for checking the Out Of Memory (OOM) thread task.</p>
If no parameter is specified, this command displays the current OOM configuration.
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p749810571812"><aname="p749810571812"></a><aname="p749810571812"></a>100 to 10000</p>
> **NOTE**<br>
</td>
> If the system memory is insufficient, the system displays a message indicating the insufficiency.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p2058485315912"><aname="p2058485315912"></a><aname="p2058485315912"></a>Sets the low memory threshold (in MB).</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p1584105318917"><aname="p1584105318917"></a><aname="p1584105318917"></a>0 (disables the low memory check) to 1</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p159263241121"><aname="p159263241121"></a><aname="p159263241121"></a>Sets the PageCache reclaim threshold.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p692642412121"><aname="p692642412121"></a><aname="p692642412121"></a>Ranging from the low memory threshold to the maximum available system memory</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p9762113775517"><aname="p9762113775517"></a><aname="p9762113775517"></a>Displays help information.</p>
<tbody><trid="row502mcpsimp"><tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.1 "><pid="p583513382179"><aname="p583513382179"></a><aname="p583513382179"></a>[oom] OS is in low memory state</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p19833143819174"><aname="p19833143819174"></a><aname="p19833143819174"></a>The operating system has low memory.</p>
<pid="p83883291587"><aname="p83883291587"></a><aname="p83883291587"></a>The available physical memory in the operating system is <strongid="b15343050123397"><aname="b15343050123397"></a><aname="b15343050123397"></a>0x1bcf000</strong> bytes, <strongid="b18697901323397"><aname="b18697901323397"></a><aname="b18697901323397"></a>0x1b50000</strong> bytes have been used, and <strongid="b3252944373397"><aname="b3252944373397"></a><aname="b3252944373397"></a>0x7f000</strong> bytes are available. The current low memory threshold is <strongid="b13811086363397"><aname="b13811086363397"></a><aname="b13811086363397"></a>0x80000</strong> bytes.</p>
</td>
</tr>
<trid="row1990234224612"><tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.1 "><pid="p3902144294612"><aname="p3902144294612"></a><aname="p3902144294612"></a>[oom] candidate victim process init pid: 1, actual phy mem byte: 82602</p>
</td>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p13903144284610"><aname="p13903144284610"></a><aname="p13903144284610"></a>Memory usage of each process. The physical memory occupied by the <strongid="b143686319910"><aname="b143686319910"></a><aname="b143686319910"></a>init</strong> process is 82602 bytes.</p>
</td>
</tr>
<trid="row520212272335"><tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.1 "><pid="p172038278339"><aname="p172038278339"></a><aname="p172038278339"></a>[oom] candidate victim process UserProcess12 pid: 12, actual phy mem byte: 25951558</p>
</td>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p112034276331"><aname="p112034276331"></a><aname="p112034276331"></a>The actual memory used by the <strongid="b16405477923397"><aname="b16405477923397"></a><aname="b16405477923397"></a>UserProcess12</strong> process is <strongid="b10952024983397"><aname="b10952024983397"></a><aname="b10952024983397"></a>25951558</strong> bytes.</p>
</td>
</tr>
<trid="row3273195033416"><tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.1 "><pid="p184989213512"><aname="p184989213512"></a><aname="p184989213512"></a>[oom] max phy mem used process UserProcess12 pid: 12, actual phy mem: 25951558</p>
</td>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p112741750143417"><aname="p112741750143417"></a><aname="p112741750143417"></a>The process that uses the most memory currently is <strongid="b17770979863397"><aname="b17770979863397"></a><aname="b17770979863397"></a>UserProcess12</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p6452818367"><aname="p6452818367"></a><aname="p6452818367"></a>The system memory is low, and the <strongid="b4088490143397"><aname="b4088490143397"></a><aname="b4088490143397"></a>UserProcess12</strong> process fails to apply for memory and exits.</p>
| [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. |
| inactive anon | Number of inactive anonymous pages in the page cache.|
</td>
| active file | Number of active file pages in the page cache.|
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1058062614579"><aname="p1058062614579"></a><aname="p1058062614579"></a>Address of the physical page control block</p>
| inactive file | Number of inactive file pages in the page cache.|
</td>
| pmm 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. |
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1858082617577"><aname="p1858082617577"></a><aname="p1858082617577"></a>First physical page address, that is, start address of the physical page memory</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p85808262572"><aname="p85808262572"></a><aname="p85808262572"></a>Size of the physical page memory</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1139715117599"><aname="p1139715117599"></a><aname="p1139715117599"></a>Number of active anonymous pages in the page cache</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1341012355019"><aname="p1341012355019"></a><aname="p1341012355019"></a>Number of inactive anonymous pages in the page cache</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1267012382019"><aname="p1267012382019"></a><aname="p1267012382019"></a>Number of active file pages in the page cache</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p17966174115018"><aname="p17966174115018"></a><aname="p17966174115018"></a>Number of inactive file pages in the page cache</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1616375952018"><aname="p1616375952018"></a><aname="p1616375952018"></a><strongid="b161631659162014"><aname="b161631659162014"></a><aname="b161631659162014"></a>total</strong>: total number of physical pages.</p>
<pid="p2029802122113"><aname="p2029802122113"></a><aname="p2029802122113"></a><strongid="b429822122113"><aname="b429822122113"></a><aname="b429822122113"></a>used</strong>: number of used physical pages.</p>
<pid="p1218312452014"><aname="p1218312452014"></a><aname="p1218312452014"></a><strongid="b132798755433826"><aname="b132798755433826"></a><aname="b132798755433826"></a>free</strong>: number of free physical pages.</p>
This command is used to query information about kernel semaphores.
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 |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p455mcpsimp"><aname="p455mcpsimp"></a><aname="p455mcpsimp"></a>Specifies the semaphore ID.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p14422125918562"><aname="p14422125918562"></a><aname="p14422125918562"></a>[0, 1023] or [0x0, 0x3FF]</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p462mcpsimp"><aname="p462mcpsimp"></a><aname="p462mcpsimp"></a>Queries information about all the semaphores in use. The information includes <strongid="b189454249533849"><aname="b189454249533849"></a><aname="b189454249533849"></a>SemID</strong>, <strongid="b162724654333849"><aname="b162724654333849"></a><aname="b162724654333849"></a>Count</strong>, <strongid="b111325307233849"><aname="b111325307233849"></a><aname="b111325307233849"></a>OriginalCount</strong>, <strongid="b182850346833849"><aname="b182850346833849"></a><aname="b182850346833849"></a>Creator(TaskEntry)</strong>, and <strongid="b213750533633849"><aname="b213750533633849"></a><aname="b213750533633849"></a>LastAccessTime</strong>.</p>
- 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.
- 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**.
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**.
> 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.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p506mcpsimp"><aname="p506mcpsimp"></a><aname="p506mcpsimp"></a>Number of times that the semaphore is used</p>
>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.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1829104012416"><aname="p1829104012416"></a><aname="p1829104012416"></a>Number of times that the semaphore is used</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p282916401148"><aname="p282916401148"></a><aname="p282916401148"></a>Original count of the semaphore</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p168298407419"><aname="p168298407419"></a><aname="p168298407419"></a>Address of the entry function of the thread used to create the semaphore</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p198292406412"><aname="p198292406412"></a><aname="p198292406412"></a>Last time when the semaphore was accessed</p>
</td>
</tr>
</tbody>
</table>
| 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.|
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p647mcpsimp"><aname="p647mcpsimp"></a><aname="p647mcpsimp"></a>Name of the stack</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1510024539"><aname="p1510024539"></a><aname="p1510024539"></a>Size of the stack used</p>
<tdclass="cellrowborder"valign="top"width="51.93%"headers="mcps1.2.4.1.2 "><pid="p14138191243"><aname="p14138191243"></a><aname="p14138191243"></a>Specifies the ID of the target user.</p>
<tdclass="cellrowborder"valign="top"width="51.93%"headers="mcps1.2.4.1.2 "><pid="p48748461789"><aname="p48748461789"></a><aname="p48748461789"></a>Specifies the ID of the target user group.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p534mcpsimp"><aname="p534mcpsimp"></a><aname="p534mcpsimp"></a>Specifies the ID of a software timer.</p>
| State | Status of the software timer.<br>The status may be **UnUsed**, **Created**, or **Ticking**.|
</th>
| 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).|
</tr>
| Interval | Number of ticks for the software timer.|
</thead>
| Count | Number of times that the software timer has been used.|
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p565mcpsimp"><aname="p565mcpsimp"></a><aname="p565mcpsimp"></a>ID of the software timer</p>
</td>
> **NOTE**<br>
</tr>
> - 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.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p570mcpsimp"><aname="p570mcpsimp"></a><aname="p570mcpsimp"></a>Status of the software timer</p>
<pid="p88402543474"><aname="p88402543474"></a><aname="p88402543474"></a>The value can be <strongid="b164905263633836"><aname="b164905263633836"></a><aname="b164905263633836"></a>UnUsed</strong>, <strongid="b138979237833836"><aname="b138979237833836"></a><aname="b138979237833836"></a>Created</strong>, or <strongid="b3849463233836"><aname="b3849463233836"></a><aname="b3849463233836"></a>Ticking</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p575mcpsimp"><aname="p575mcpsimp"></a><aname="p575mcpsimp"></a>Mode of the software timer</p>
<pid="p657320204499"><aname="p657320204499"></a><aname="p657320204499"></a>The value can be <strongid="b201632419733836"><aname="b201632419733836"></a><aname="b201632419733836"></a>Once</strong>, <strongid="b45281151733836"><aname="b45281151733836"></a><aname="b45281151733836"></a>Period</strong>, or <strongid="b73443815433836"><aname="b73443815433836"></a><aname="b73443815433836"></a>NSD</strong> (one-shot timer that will not be automatically deleted after the timer has expired).</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p580mcpsimp"><aname="p580mcpsimp"></a><aname="p580mcpsimp"></a>Number of ticks for the software timer</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p585mcpsimp"><aname="p585mcpsimp"></a><aname="p585mcpsimp"></a>Number of times that the software timer has been used</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p595mcpsimp"><aname="p595mcpsimp"></a><aname="p595mcpsimp"></a>Address of the callback</p>
>- 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.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p662mcpsimp"><aname="p662mcpsimp"></a><aname="p662mcpsimp"></a>Whether the module is enabled</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p689mcpsimp"><aname="p689mcpsimp"></a><aname="p689mcpsimp"></a>Displays all information.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1062611511398"><aname="p1062611511398"></a><aname="p1062611511398"></a>Parent process ID</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p2068355383916"><aname="p2068355383916"></a><aname="p2068355383916"></a>Process group ID</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p2011611331604"><aname="p2011611331604"></a><aname="p2011611331604"></a>CPU usage within last 10 seconds</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p843mcpsimp"><aname="p843mcpsimp"></a><aname="p843mcpsimp"></a>Size of the task stack</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p848mcpsimp"><aname="p848mcpsimp"></a><aname="p848mcpsimp"></a>Peak value of the stack used</p>
<tdclass="cellrowborder"valign="top"width="29.222922292229224%"headers="mcps1.2.5.1.2 "><pid="p942673885313"><aname="p942673885313"></a><aname="p942673885313"></a>Displays the parameters supported by the <strongid="b2435956125215"><aname="b2435956125215"></a><aname="b2435956125215"></a>top</strong> command.</p>
</td>
Currently, the shell does not support this command. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p19723153055519"><aname="p19723153055519"></a><aname="p19723153055519"></a>Parent process ID</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p117231630165519"><aname="p117231630165519"></a><aname="p117231630165519"></a>Process group ID</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1172323019556"><aname="p1172323019556"></a><aname="p1172323019556"></a>CPU usage within last 10 seconds</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p8724930135519"><aname="p8724930135519"></a><aname="p8724930135519"></a>Size of the task stack</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p10724103013559"><aname="p10724103013559"></a><aname="p10724103013559"></a>Peak value of the stack used</p>
<tdclass="cellrowborder"valign="top"width="66.01%"headers="mcps1.2.3.1.2 "><pid="p1664862551411"><aname="p1664862551411"></a><aname="p1664862551411"></a>Displays help information.</p>
| -m | Displays the operating system architecture name. |
</td>
| -n | Displays the network domain name of the host. |
<tdclass="cellrowborder"valign="top"width="66.01%"headers="mcps1.2.3.1.2 "><pid="p186484252141"><aname="p186484252141"></a><aname="p186484252141"></a>Displays the operating system name by default.</p>
## Usage Guidelines
</td>
</tr>
- 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**.
<tdclass="cellrowborder"valign="top"width="66.01%"headers="mcps1.2.3.1.2 "><pid="p864872512145"><aname="p864872512145"></a><aname="p864872512145"></a>Displays all information.</p>
The **-r**, **-m**, and **-n** parameters are not supported currently. mksh supports these parameters. To switch to mksh, run **cd bin** and **./mksh**.
</td>
<tdclass="cellrowborder"valign="top"width="66.01%"headers="mcps1.2.3.1.2 "><pid="p1064852514149"><aname="p1064852514149"></a><aname="p1064852514149"></a>Displays the operating system name.</p>
<tdclass="cellrowborder"valign="top"width="66.01%"headers="mcps1.2.3.1.2 "><pid="p136489251143"><aname="p136489251143"></a><aname="p136489251143"></a>Displays the operating system architecture name.</p>
<tdclass="cellrowborder"valign="top"width="66.01%"headers="mcps1.2.3.1.2 "><pid="p6648132512141"><aname="p6648132512141"></a><aname="p6648132512141"></a>Displays the network domain name of the host.</p>
<tdclass="cellrowborder"valign="top"width="66.01%"headers="mcps1.2.3.1.2 "><pid="p46489250149"><aname="p46489250149"></a><aname="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>
Run the following commands:
Run the following commands:
- uname -a
- uname -a
- uname -ms
- uname -ms
## Output<a name="section1215113245511"></a>
## Output
Example 1: all information of the operating system
Example 1: all information of the operating system
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p209441344121716"><aname="p209441344121716"></a><aname="p209441344121716"></a>Displays the virtual memory usage of all processes.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1494494441713"><aname="p1494494441713"></a><aname="p1494494441713"></a>Displays help information.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1594515442177"><aname="p1594515442177"></a><aname="p1594515442177"></a>Specifies the ID of the process to query.</p>
| region | Address of the control block in the virtual memory region.|
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p9137130122311"><aname="p9137130122311"></a><aname="p9137130122311"></a>Address of the virtual memory control block</p>
| name | Name of the virtual memory region.|
</td>
| base | Start address of the virtual memory region.|
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1613783082319"><aname="p1613783082319"></a><aname="p1613783082319"></a>Start address of the virtual memory</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p18137143092313"><aname="p18137143092313"></a><aname="p18137143092313"></a>Size of virtual memory</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p5137130142314"><aname="p5137130142314"></a><aname="p5137130142314"></a>Number of used physical pages</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1795344642412"><aname="p1795344642412"></a><aname="p1795344642412"></a>Address of the control block in the virtual memory region</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p19539466245"><aname="p19539466245"></a><aname="p19539466245"></a>Name of the virtual memory region</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p139536468242"><aname="p139536468242"></a><aname="p139536468242"></a>Start address of the virtual memory region</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p89531246142419"><aname="p89531246142419"></a><aname="p89531246142419"></a>Size of the virtual memory region</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p395464620242"><aname="p395464620242"></a><aname="p395464620242"></a>MMU mapping attribute of the virtual memory region</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p29541546112416"><aname="p29541546112416"></a><aname="p29541546112416"></a>Number of used physical pages, including that of the shared memory</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p10954164642419"><aname="p10954164642419"></a><aname="p10954164642419"></a>Number of used physical pages</p>
<tdclass="cellrowborder"valign="top"width="29.222922292229224%"headers="mcps1.2.5.1.2 "><pid="p986mcpsimp"><aname="p986mcpsimp"></a><aname="p986mcpsimp"></a>Specifies the number of times that the specified command is executed.</p>
</td>
You can run the **watch --over** command to stop monitoring of the specified command.
<tdclass="cellrowborder"valign="top"width="29.222922292229224%"headers="mcps1.2.5.1.2 "><pid="p995mcpsimp"><aname="p995mcpsimp"></a><aname="p995mcpsimp"></a>Specifies the interval (in seconds) for periodically running the specified command.</p>
<tdclass="cellrowborder"valign="top"width="29.222922292229224%"headers="mcps1.2.5.1.2 "><pid="p1004mcpsimp"><aname="p1004mcpsimp"></a><aname="p1004mcpsimp"></a>Disables time display on the top.</p>
<tdclass="cellrowborder"valign="top"width="29.222922292229224%"headers="mcps1.2.5.1.2 "><pid="p1013mcpsimp"><aname="p1013mcpsimp"></a><aname="p1013mcpsimp"></a>Specifies the command to be monitored.</p>
<tdclass="cellrowborder"valign="top"width="29.222922292229224%"headers="mcps1.2.5.1.2 "><pid="p1022mcpsimp"><aname="p1022mcpsimp"></a><aname="p1022mcpsimp"></a>Stops the current command monitoring.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1066mcpsimp"><aname="p1066mcpsimp"></a><aname="p1066mcpsimp"></a>Specifies the file path.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1104mcpsimp"><aname="p1104mcpsimp"></a><aname="p1104mcpsimp"></a>Specifies the target file path.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p1106mcpsimp"><aname="p1106mcpsimp"></a><aname="p1106mcpsimp"></a>You must have the execution (search) permission for the specified directory.</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section3629759111317"></a>
**Table 1** Parameter description
- If **path** is not specified, this command switches to the root directory.
| Parameter| Description| Value Range|
- If **path** is specified, this command switches to the specified directory.
| -------- | -------- | -------- |
- The **path** value starting with a slash \(/\) represents the root directory.
| path | Specifies the path of the new directory. | You must have the execution (search) permission on the specified 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<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.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p4218826194210"><aname="p4218826194210"></a><aname="p4218826194210"></a>Specifies the file path.</p>
| 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 |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3911344161713"><aname="p3911344161713"></a><aname="p3911344161713"></a>Specifies the permissions for a file or directory. The value is an octal number, representing the permission of <strongid="b11602834153114"><aname="b11602834153114"></a><aname="b11602834153114"></a>User</strong> (owner), <strongid="b032113853120"><aname="b032113853120"></a><aname="b032113853120"></a>Group</strong> (group), or <strongid="b1980114418310"><aname="b1980114418310"></a><aname="b1980114418310"></a>Others</strong> (other groups).</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p149134481719"><aname="p149134481719"></a><aname="p149134481719"></a>Specifies the file name.</p>
- 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.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p14126172111"><aname="p14126172111"></a><aname="p14126172111"></a>Specifies the file owner.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p7412315218"><aname="p7412315218"></a><aname="p7412315218"></a>Specifies the file path.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p181687882317"><aname="p181687882317"></a><aname="p181687882317"></a>Displays help information.</p>
- 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.
</td>
</tr>
- 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.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p81686862314"><aname="p81686862314"></a><aname="p81686862314"></a>Specifies the path of the source file.</p>
</td>
- If the destination file path is a file, the directory for this file must exist. In this case, the file copy is renamed.
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p1016811862312"><aname="p1016811862312"></a><aname="p1016811862312"></a>This command does not support copy of a directory, but supports copy of multiple files at a time.</p>
</td>
- If the destination file does not exist, a new file is created. If the destination file already exists, the existing file is overwritten.
> 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.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p9168789231"><aname="p9168789231"></a><aname="p9168789231"></a>Specifies the destination file path.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p316810810235"><aname="p316810810235"></a><aname="p316810810235"></a>Both a directory and a file are supported.</p>
## Example
</td>
</tr>
Run **cp hello-OHOS.txt hello-openharmony.txt ./tmp/**.
</tbody>
</table>
## Output
## Usage<a name="section16128156162"></a>
Copy **hello-OHOS.txt** and **hello-openharmony.txt** to **/tmp/**.
- 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.
>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/**:
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p14216153332715"><aname="p14216153332715"></a><aname="p14216153332715"></a>Displays the parameters supported by the <strongid="b22402916307"><aname="b22402916307"></a><aname="b22402916307"></a>du</strong> command.</p>
- The value of **file** must be the file name. It cannot contain the directory where the file is located.
</td>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p142161833172710"><aname="p142161833172710"></a><aname="p142161833172710"></a>Displays the occupied blocks, each of which is 1024 bytes by default.</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p13216103319274"><aname="p13216103319274"></a><aname="p13216103319274"></a>Displays the occupied blocks, each of which is 512 bytes (POSIX).</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p621673332720"><aname="p621673332720"></a><aname="p621673332720"></a>Displays the disk space in MB.</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p2216533192717"><aname="p2216533192717"></a><aname="p2216533192717"></a>Displays the disk space in human-readable format K, M, and G, for example, <strongid="b1315823125013"><aname="b1315823125013"></a><aname="b1315823125013"></a>1K</strong>, <strongid="b385962710225"><aname="b385962710225"></a><aname="b385962710225"></a>243M</strong>, or <strongid="b1114122962214"><aname="b1114122962214"></a><aname="b1114122962214"></a>2G</strong>.</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p19216103310272"><aname="p19216103310272"></a><aname="p19216103310272"></a>Specifies the target file.</p>
| 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. |
</thead>
| 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. |
</td>
<tdclass="cellrowborder"valign="top"width="66%"headers="mcps1.2.3.1.2 "><pid="p1197mcpsimp"><aname="p1197mcpsimp"></a><aname="p1197mcpsimp"></a>Specifies the device name.</p>
- 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.
</td>
<tdclass="cellrowborder"valign="top"width="66%"headers="mcps1.2.3.1.2 "><pid="p1207mcpsimp"><aname="p1207mcpsimp"></a><aname="p1207mcpsimp"></a>Specifies the size of the allocated memory unit or sector. The value <strongid="b1574273871018"><aname="b1574273871018"></a><aname="b1574273871018"></a>0</strong> indicates null. (The value must be <strongid="b16428721113"><aname="b16428721113"></a><aname="b16428721113"></a>0</strong> or a power of <strongid="b1053419931111"><aname="b1053419931111"></a><aname="b1053419931111"></a>2</strong>. For FAT32, the maximum value is <strongid="b51473841110"><aname="b51473841110"></a><aname="b51473841110"></a>128</strong>. If the parameter is set to <strongid="b99547931214"><aname="b99547931214"></a><aname="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>
- The **format** command can be used to format the USB flash drive, SD card, and MMC, but not the NAND flash or NOR flash.
</td>
</tr>
- An invalid **sectors** value may cause exceptions.
<tdclass="cellrowborder"valign="top"width="66%"headers="mcps1.2.3.1.2 "><divclass="p"id="p1212mcpsimp"><aname="p1212mcpsimp"></a><aname="p1212mcpsimp"></a>Specifies the file system type. The options are as follows:<aname="ul10971366369"></a><aname="ul10971366369"></a><ulid="ul10971366369"><li><strongid="b169384514517"><aname="b169384514517"></a><aname="b169384514517"></a>0x01</strong>: FMT_FAT</li><li><strongid="b143061510125114"><aname="b143061510125114"></a><aname="b143061510125114"></a>0x02</strong>: FMT_FAT32</li><li><strongid="b3245614165116"><aname="b3245614165116"></a><aname="b3245614165116"></a>0x07</strong>: FMT_ANY</li><li><strongid="b018121813512"><aname="b018121813512"></a><aname="b018121813512"></a>0x08</strong>: FMT_ERASE (not supported by the USB flash drive)</li></ul>
## Example
</div>
<pid="p28366459374"><aname="p28366459374"></a><aname="p28366459374"></a>If an invalid value is specified, the system automatically selects the formatting mode. If the low-level formatting bit is <strongid="b4634562520"><aname="b4634562520"></a><aname="b4634562520"></a>1</strong> during the formatting of a USB flash drive, an error message is printed.</p>
<tdclass="cellrowborder"valign="top"width="66%"headers="mcps1.2.3.1.2 "><pid="p1217mcpsimp"><aname="p1217mcpsimp"></a><aname="p1217mcpsimp"></a>Specifies the volume label name. This parameter is optional, and the value is a string. If <strongid="b16648426102713"><aname="b16648426102713"></a><aname="b16648426102713"></a>null</strong> is specified for this parameter, the previously set volume label name is cleared.</p>
Format an MMC.
</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.
ls [_-ACHLSZacdfhiklmnopqrstux1_] [_--color_[_=auto_]] [_directory..._]
>During the system boot process, **ls=toybox ls --color=auto**, **ll = ls -alF**, **la=ls -A**, and **l=ls -CF** commands have been enabled using **alias** so that the initial actions of these commands are the same as those on Linux. For details, see the output description. To view help information, run **toybox ls --help**.
> **NOTE**<br>
## Parameters<a name="section17528148171617"></a>
> During the system boot process, **ls=toybox ls --color=auto**, **ll = ls -alF**, **la=ls -A**, and **l=ls -CF** commands have been enabled using **alias** so that the initial actions of these commands are the same as those on Linux. For details, see **Output**. To view help information, run **toybox ls --help**.
| -d | Displays only the directory, rather than listing the content of the directory. | N/A |
</td>
| -i | Displays the node ID of a file. | N/A |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p161410110302"><aname="p161410110302"></a><aname="p161410110302"></a>Displays parameters supported by the <strongid="b05047195230"><aname="b05047195230"></a><aname="b05047195230"></a>ls</strong> command and their usage.</p>
| -p | Adds a slash (/) after the directory. | N/A |
</td>
| -q | Displays non-printable characters, such as "?". | N/A |
| -H | Follows symbolic links listed in the command line. | N/A |
</td>
| -L | Follows symbolic links. | N/A |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p861431163012"><aname="p861431163012"></a><aname="p861431163012"></a>Displays all files, including .hidden files.</p>
| -Z | Displays security context. | N/A |
</td>
| path | Specifies the path of the target directory.<br/>If **path** is left blank, the content of the current directory is displayed.<br>If **path** is an invalid directory, "ls error: No such directory." is displayed.<br><br>If **path** is a valid directory, the content of the specified directory is displayed. | Left blank<br>A valid directory|
| -m | Fills width with a list of entries separated by a comma. |
</td>
| -n | Like **-l**, but lists numeric user and group IDs.|
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p6615121114307"><aname="p6615121114307"></a><aname="p6615121114307"></a>Uses ctime as the file timestamp. This parameter must be used together with <strongid="b644143217354"><aname="b644143217354"></a><aname="b644143217354"></a>-l</strong>.</p>
| -o | Like **-l**, but do not list group information. |
</td>
| -x | Lists entries by line, instead of by column. |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p126151511193010"><aname="p126151511193010"></a><aname="p126151511193010"></a>Displays only the directory, rather than listing the content of the directory.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p11615511193012"><aname="p11615511193012"></a><aname="p11615511193012"></a>Displays the node ID of a file.</p>
| --color | device=yellow symlink=turquoise/red dir=blue socket=purple files: exe=green suid=red suidfile=redback stickydir=greenback=auto means detect if output is a tty. |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3615131103017"><aname="p3615131103017"></a><aname="p3615131103017"></a>Adds a slash (/) after the directory.</p>
The file node information of the FAT file system inherits from its parent node. The parent node ID is **0**. Therefore, if you run the **ls -i** command on the Hi3516D V300 development board, the file node IDs displayed are all **0**.
The shell does not support **ls** parameters. mksh supports them. To switch to mksh, run **cd bin** and **./mksh**.
</td>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p19615511123011"><aname="p19615511123011"></a><aname="p19615511123011"></a>Displays non-printable characters, such as "?".</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p161511114303"><aname="p161511114303"></a><aname="p161511114303"></a>Provides information about the memory occupied by the directory and its members, in 1024 bytes.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p761501113306"><aname="p761501113306"></a><aname="p761501113306"></a>Uses the last access time of the file as the timestamp. This option is used together with <strongid="b83441545164512"><aname="b83441545164512"></a><aname="b83441545164512"></a>-l</strong>.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p56151511183019"><aname="p56151511183019"></a><aname="p56151511183019"></a>Lists all files except implied . and ..</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p19615151118304"><aname="p19615151118304"></a><aname="p19615151118304"></a>Follows symbolic links listed in the command line.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1761611110307"><aname="p1761611110307"></a><aname="p1761611110307"></a>If <strongid="b115515262034"><aname="b115515262034"></a><aname="b115515262034"></a>path</strong> is left blank, the content of the current directory is displayed.</p>
<pid="p10616141117308"><aname="p10616141117308"></a><aname="p10616141117308"></a>If <strongid="b9593204114312"><aname="b9593204114312"></a><aname="b9593204114312"></a>path</strong> is an invalid file name, the following failure message is displayed:</p>
<pid="p1061631112303"><aname="p1061631112303"></a><aname="p1061631112303"></a><strongid="b19604131716416"><aname="b19604131716416"></a><aname="b19604131716416"></a>ls error: No such directory</strong></p>
<pid="p206161111143018"><aname="p206161111143018"></a><aname="p206161111143018"></a>If <strongid="b615314272412"><aname="b615314272412"></a><aname="b615314272412"></a>path</strong> is a valid directory, the content of that directory is displayed.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p761617115309"><aname="p761617115309"></a><aname="p761617115309"></a>Left blank or a valid directory</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1865811565309"><aname="p1865811565309"></a><aname="p1865811565309"></a>Lists one file per line.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1065865611302"><aname="p1065865611302"></a><aname="p1065865611302"></a>Lists entries by column.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p20658356183018"><aname="p20658356183018"></a><aname="p20658356183018"></a>Like <strongid="b206161282355"><aname="b206161282355"></a><aname="b206161282355"></a>-l</strong>, but do not list owner.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p16581756143014"><aname="p16581756143014"></a><aname="p16581756143014"></a>Displays the total size of files in the directory, in KiB.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1465875603018"><aname="p1465875603018"></a><aname="p1465875603018"></a>Displays detailed information about files in the directory.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p15658115620304"><aname="p15658115620304"></a><aname="p15658115620304"></a>Fills width with a list of entries separated by a comma.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1465895663016"><aname="p1465895663016"></a><aname="p1465895663016"></a>Like <strongid="b88319189351"><aname="b88319189351"></a><aname="b88319189351"></a>-l</strong>, but lists numeric user and group IDs.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p12658956193017"><aname="p12658956193017"></a><aname="p12658956193017"></a>Like <strongid="b24118395354"><aname="b24118395354"></a><aname="b24118395354"></a>-l</strong>, but do not list group information.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p13658456123014"><aname="p13658456123014"></a><aname="p13658456123014"></a>Lists entries by line, instead of by column.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p365855610302"><aname="p365855610302"></a><aname="p365855610302"></a>Lists the file time attribute as ns.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p2659756123020"><aname="p2659756123020"></a><aname="p2659756123020"></a>Colorizes the output.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p2659135633011"><aname="p2659135633011"></a><aname="p2659135633011"></a>Default value: device=yellow symlink=turquoise/red dir=blue socket=purple files: exe=green suid=red suidfile=redback stickydir=greenback=auto means detect if output is a tty.</p>
</td>
</tr>
</tbody>
</table>
**Table 3** Sorting parameters \(sorted by the initial letter by default\)
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p18344132717315"><aname="p18344132717315"></a><aname="p18344132717315"></a>Do not sort.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p11344102743115"><aname="p11344102743115"></a><aname="p11344102743115"></a>Reverse order while sorting.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p10344727103114"><aname="p10344727103114"></a><aname="p10344727103114"></a>Sort by time, newest first.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1134452715312"><aname="p1134452715312"></a><aname="p1134452715312"></a>Sort by file size, largest first.</p>
>The file node information of the FAT file system inherits from its parent node. The parent node ID is **0**. Therefore, if you run the **ls -i** command on the Hi3516D V300 development board, the file node IDs displayed are all **0**.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p2053354433413"><aname="p2053354433413"></a><aname="p2053354433413"></a>Displays the parameters supported by the <strongid="b1177313015559"><aname="b1177313015559"></a><aname="b1177313015559"></a>mkdir</strong> command.</p>
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.
</td>
</tr>
In addition, only the user read and write permissions can be modified. The read and write permissions are **rw** and **ro** only. Therefore, when the **-m** option is specified in the **mkdir** command, only **777** and **555** permissions are available for the created directory, and the execute permission does not take effect.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p9533114416343"><aname="p9533114416343"></a><aname="p9533114416343"></a>Sets the permissions on the directory to create.</p>
</td>
Currently, the shell does not support this command. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p453344420349"><aname="p453344420349"></a><aname="p453344420349"></a>Prints detailed information about the directory creation process.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p653315443342"><aname="p653315443342"></a><aname="p653315443342"></a>Specifies the directory to create.</p>
>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. Therefore, when the **-m** option is specified in the **mkdir** command, only **777** and **555** permissions are available for the created directory, and the execute permission does not take effect.
## Example<a name="section1113345211713"></a>
Run the following commands:
Run the following commands:
- mkdir testpath
- mkdir testpath
- mkdir -m 777 testpath
- mkdir -pv testpath01/testpath02/testpath03
- mkdir -m 777 testpath
- mkdir -pv testpath01/testpath02/testpath03
## Output
Example 1: Create a directory named **testpath**.
## Output<a name="section10142201012"></a>
```
```
OHOS:/tmp$ mkdir testpath
OHOS:/tmp$ mkdir testpath
...
@@ -83,7 +56,8 @@ total 2
...
@@ -83,7 +56,8 @@ total 2
drwxrwxrwx 1 0 0 2048 1979-12-31 00:00 testpath/
drwxrwxrwx 1 0 0 2048 1979-12-31 00:00 testpath/
```
```
Example 2: creating a directory with specified permissions
Example 2: Create a directory named **testpath** with specified permissions.
| DIR | Specifies the directory.<br>You must have the execution (search) permission on the specified directory.| N/A |
</td>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p8804113024018"><aname="p8804113024018"></a><aname="p8804113024018"></a>Displays the parameters supported by the <strongid="b07421044122514"><aname="b07421044122514"></a><aname="b07421044122514"></a>mount</strong> command.</p>
By specifying the device to mount, directory, and file system format in the **mount** command, you can successfully mount the file system to the specified directory.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1980419305409"><aname="p1980419305409"></a><aname="p1980419305409"></a>Fakes mounting the file system (no mounting is actually performed).</p>
Currently, the shell does not support this command. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p680443010409"><aname="p680443010409"></a><aname="p680443010409"></a>Specifies the file system type.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p280473015402"><aname="p280473015402"></a><aname="p280473015402"></a>Specifies the mount options.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p28045303401"><aname="p28045303401"></a><aname="p28045303401"></a>Specifies the device to mount (in the format of the device directory).</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p8804113084010"><aname="p8804113084010"></a><aname="p8804113084010"></a>A device in the system</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1380419308409"><aname="p1380419308409"></a><aname="p1380419308409"></a>Specifies the directory.</p>
<pid="p14804153014011"><aname="p14804153014011"></a><aname="p14804153014011"></a>You must have the execution (search) permission on the specified directory.</p>
By specifying the device to mount, directory, and file system format in the **mount** command, you can successfully mount the file system to the specified directory.
## Example<a name="section7424625171917"></a>
Run **mount -t nfs 192.168.1.3:/nfs nfs**.
## Output<a name="section14757018116"></a>
Mounting the **nfs** directory on the server with IP address of **192.168.1.3** to the newly created **/nfs** directory in the current system
| -i | Provides information before moving a file that would overwrite an existing file or directory. Enter **y** to overwrite the file or directory, and enter **n** to cancel the operation.| N/A |
</tr>
| -n | Do not overwrite any existing file or directory. | N/A |
</thead>
| -v | This parameter does not take effect although it is supported by the latest Toybox code. | N/A |
| SOURCE | Specifies the file to move. | This command cannot be used to move a directory. It can be used to move multiple files at a time.|
</td>
| DEST | Specifies the destination file path. | Both a directory and a file are supported. |
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p1165745918447"><aname="p1165745918447"></a><aname="p1165745918447"></a>Displays help information.</p>
-**SOURCEFILE** supports wildcard characters * and ?. The asterisk (*) indicates any number of characters, and the question mark (?) represents a single character. **DEST** does not support wildcard characters. If the specified **SOURCE** matches multiple files, **DEST** must be a directory.
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p7657105917445"><aname="p7657105917445"></a><aname="p7657105917445"></a>Provides a prompt before moving a file that would overwrite an existing file. Enter <strongid="b886564463218"><aname="b886564463218"></a><aname="b886564463218"></a>y</strong> to overwrite the file or enter <strongid="b16826758113218"><aname="b16826758113218"></a><aname="b16826758113218"></a>n</strong> to cancel the operation.</p>
Currently, the shell does not support this command. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p36572059164415"><aname="p36572059164415"></a><aname="p36572059164415"></a>Do not overwrite any existing file or directory.</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p166571759124418"><aname="p166571759124418"></a><aname="p166571759124418"></a>This parameter does not take effect although it is supported by the latest Toybox code.</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p3657205924416"><aname="p3657205924416"></a><aname="p3657205924416"></a>Specifies the path of the source file.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p1365775904419"><aname="p1365775904419"></a><aname="p1365775904419"></a>This command cannot be used to move a directory. It can be used to move multiple files at a time.</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p265810599448"><aname="p265810599448"></a><aname="p265810599448"></a>Specifies the destination file path.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p7658105914449"><aname="p7658105914449"></a><aname="p7658105914449"></a>Both a directory and a file are supported.</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section19190125723612"></a>
-**SOURCE** supports wildcard characters \* and ?. The asterisk \(\*\) indicates any number of characters, and the question mark \(?\) represents a 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 **DEST** is a file, the directory for this file must exist.
- If the destination file already exists, it will be overwritten.
## Example<a name="section10383416372"></a>
Run the following commands:
Run the following commands:
- mv -i test.txt testpath/
- mv -i test.txt testpath/
- mv test?.txt testpath/ \(Move **test3.txt**, **testA.txt**, and **test\_.txt**\)
## Output<a name="section131601649114511"></a>
- mv test?.txt testpath/ (Move **test3.txt**, **testA.txt**, and **test_.txt**)
<tdclass="cellrowborder"valign="top"width="51%"headers="mcps1.2.4.1.2 "><pid="p1407mcpsimp"><aname="p1407mcpsimp"></a><aname="p1407mcpsimp"></a>Specifies the name of the partition to be queried.</p>
The **pwd** command writes the full path (from the root directory) of the current directory to the standard output. The directories are separated by slashes (/). The directory following the first slash (/) indicates the root directory, and the last directory is the current directory.
The **pwd** command writes the full path \(from the root directory\) of the current directory to the standard output. The directories are separated by slashes \(/\). The directory following the first slash \(/\) indicates the root directory, and the last directory is the current directory.
- If the **rm** command without **-f** is used to delete a file that does not exist, an error will be reported.
</td>
<tdclass="cellrowborder"valign="top"width="51.519999999999996%"headers="mcps1.2.4.1.2 "><pid="p53092373308"><aname="p53092373308"></a><aname="p53092373308"></a>Deletes a file or directory forcibly without confirmation. No error will be reported when a file that does not exist is to be deleted.</p>
<tdclass="cellrowborder"valign="top"width="51.519999999999996%"headers="mcps1.2.4.1.2 "><pid="p1830913711300"><aname="p1830913711300"></a><aname="p1830913711300"></a>Displays the deletion process.</p>
<tdclass="cellrowborder"valign="top"width="51.519999999999996%"headers="mcps1.2.4.1.2 "><pid="p193091637183016"><aname="p193091637183016"></a><aname="p193091637183016"></a>Specifies the name of the file or directory to delete. The value can be a path.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p18752121015338"><aname="p18752121015338"></a><aname="p18752121015338"></a>Displays the parameters supported by the <strongid="b101038101521"><aname="b101038101521"></a><aname="b101038101521"></a>rmdir</strong> command.</p>
</td>
- The **rmdir** command can only be used to delete directories.
- The **rmdir** command can delete only empty directories.
</td>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1475271013319"><aname="p1475271013319"></a><aname="p1475271013319"></a>Deletes a path.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p77522010123314"><aname="p77522010123314"></a><aname="p77522010123314"></a>Suppresses the error message when a non-empty directory is to be deleted.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p3752161083313"><aname="p3752161083313"></a><aname="p3752161083313"></a>Specifies the name of the directory to delete. The directory must be empty. A path is supported.</p>
<tdclass="cellrowborder"valign="top"width="33.33333333333333%"headers="mcps1.2.4.1.2 "><pid="p1615mcpsimp"><aname="p1615mcpsimp"></a><aname="p1615mcpsimp"></a>Specifies the file system directory.</p>
</td>
<tdclass="cellrowborder"valign="top"width="33.33333333333333%"headers="mcps1.2.4.1.3 "><pid="p1617mcpsimp"><aname="p1617mcpsimp"></a><aname="p1617mcpsimp"></a>The file system must exist and support the <strongid="b1635148125717"><aname="b1635148125717"></a><aname="b1635148125717"></a>statfs</strong> command. The supported file systems include JFFS2, FAT, and NFS.</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section133816772712"></a>
**Table 1** Parameter description
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| directory | Specifies the file system directory.| The file system must exist and support the **statfs** command. The supported file systems include JFFS2, FAT, and NFS.|
## Usage Guidelines
The printed information varies depending on the file system.
The printed information varies depending on the file system.
This command is used to synchronize cached data \(data in the file system\) to an SD card.
This command is used to synchronize cached data (data in the file system) to an SD card.
## Syntax<a name="section4731516162712"></a>
## Syntax
sync
sync
## Parameters<a name="section9352418122714"></a>
None
## Parameters
None.
## Usage Guidelines
- The **sync** command is used to refresh the cache. If no SD card is inserted, no operation will be performed.
## Usage<a name="section10725192142717"></a>
- When an SD card is inserted, the cache information is synchronized to the SD card. If the synchronization is successful, no information is displayed.
- The **sync** command is used to refresh the cache. If no SD card is inserted, no operation will be performed.
- When an SD card is inserted, the cache information is synchronized to the SD card. If the synchronization is successful, no information is displayed.
## Example<a name="section414434814354"></a>
## Example
Run **sync**. Data will be synchronized to the SD card if an SD card is available, and no operation will be performed if no SD card is available.
Run **sync**. Data will be synchronized to the SD card if an SD card is available, and no operation will be performed if no SD card is available.
<tdclass="cellrowborder"valign="top"width="52.44%"headers="mcps1.2.4.1.2 "><pid="p1122915417465"><aname="p1122915417465"></a><aname="p1122915417465"></a>Displays the parameters supported by the <strongid="b39321953125917"><aname="b39321953125917"></a><aname="b39321953125917"></a>touch</strong> command.</p>
<tdclass="cellrowborder"valign="top"width="52.44%"headers="mcps1.2.4.1.2 "><pid="p162291494614"><aname="p162291494614"></a><aname="p162291494614"></a>Specifies the name of the file to create.</p>
>If you run the **touch** command to create a file in a directory storing important system resources, unexpected results such as a system breakdown may occur. For example, if you run the **touch uartdev-0** command in the **/dev** directory, the system may stop responding.
| --help | Displays the parameters supported by the **touch** command.| N/A |
| filename | Specifies the name of the file to create. | N/A |
## Example<a name="section414434814354"></a>
## Usage Guidelines
- The **touch** command creates an empty file that is readable and writeable.
- You can use the **touch** command to create multiple files at a time.
> **NOTICE**<br>
> If you run the **touch** command to create a file in a directory storing important system resources, unexpected results such as a system breakdown may occur. For example, if you run the **touch uartdev-0** command in the **/dev** directory, the system may stop responding.
## Note
The shell does not support **--help** or creation of multiple files at the same time. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
## Example
Run the following commands:
Run the following commands:
- touch file.c
- touch file.c
- touch testfile1 testfile2 testfile3
## Output<a name="section1028419515711"></a>
- touch testfile1 testfile2 testfile3
## Output
Example 1: Create a file named **file.c**.
Example 1: creating the **file.c** file
```
```
OHOS:/tmp$ ls
OHOS:/tmp$ ls
...
@@ -70,7 +60,8 @@ total 0
...
@@ -70,7 +60,8 @@ total 0
-rwxrwxrwx 1 0 0 0 1979-12-31 00:00 file.c*
-rwxrwxrwx 1 0 0 0 1979-12-31 00:00 file.c*
```
```
Example 2: creating three files \(**testfile1**, **testfile2**, and **testfile3**\)
Example 2: Create three files (**testfile1**, **testfile2**, and **testfile3**) at a time.
| -t | Used together with the **-a** option to restrict the file systems specified by **-a**, allowing only the file system specified by **-t** to be unmounted.| N/A |
</tr>
| dir | Specifies the directory from which the file system is to be unmounted. | Directory mounted with the file system|
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p5999201625017"><aname="p5999201625017"></a><aname="p5999201625017"></a>Displays the parameters supported by the <strongid="b15196112818310"><aname="b15196112818310"></a><aname="b15196112818310"></a>umount</strong> command.</p>
</td>
By specifying the **dir** parameter in the **unmount** command, you can unmount the specified file system.
The shell does not support this command. mksh supports it. To switch to mksh, run **cd bin** and **./mksh**.
</td>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p159991716125019"><aname="p159991716125019"></a><aname="p159991716125019"></a>Unmounts all file systems mounted.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p49997167506"><aname="p49997167506"></a><aname="p49997167506"></a>Used together with the <strongid="b19922101571717"><aname="b19922101571717"></a><aname="b19922101571717"></a>-a</strong> option to restrict the file systems specified by <strongid="b1927154112172"><aname="b1927154112172"></a><aname="b1927154112172"></a>-a</strong>, allowing only the file system specified by <strongid="b99221198185"><aname="b99221198185"></a><aname="b99221198185"></a>-t</strong> to be unmounted.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p129991162504"><aname="p129991162504"></a><aname="p129991162504"></a>Specifies the directory from which the file system is to be unmounted.</p>
</td>
<tdclass="cellrowborder"valign="top"width="27%"headers="mcps1.2.4.1.3 "><pid="p1499916164502"><aname="p1499916164502"></a><aname="p1499916164502"></a>Directory mounted with the file system</p>
</td>
</tr>
</tbody>
</table>
## Usage<a name="section92931509368"></a>
By specifying the **dir** parameter in the **unmount** command, you can unmount the specified file system from the directory.
## Example<a name="section144311323616"></a>
Run the following commands:
Run the following commands:
- umount ./nfs
- umount ./nfs
- umount -a -t nfs
- umount -a -t nfs
## Output<a name="section360525113611"></a>
**unmount** command output:
## Output
Example 1: Unmount the file system from **./nfs**.
Example 1: unmounting the file system from **./nfs**
This command is used to write data to a specified proc file system. The proc file system supports the input of string parameters. Each file needs to implement its own method.
This command is used to write data to the specified proc file system. The proc file system supports data of strings. The method for writing data needs to be implemented.
<tdclass="cellrowborder"valign="top"width="52.970000000000006%"headers="mcps1.2.4.1.2 "><pid="p1149945111817"><aname="p1149945111817"></a><aname="p1149945111817"></a>Specifies the string to be entered, which ends with a space. If you need to enter a space, use <strongid="b11296145424918"><aname="b11296145424918"></a><aname="b11296145424918"></a>""</strong> to enclose the space.</p>
<tdclass="cellrowborder"valign="top"width="52.970000000000006%"headers="mcps1.2.4.1.2 "><pid="p25985252238"><aname="p25985252238"></a><aname="p25985252238"></a>Specifies the proc file to which <strongid="b1319518261507"><aname="b1319518261507"></a><aname="b1319518261507"></a>data</strong> is to be passed.</p>
>The procfs file system does not support multi-thread access.
## Example<a name="section79281818476"></a>
## Usage Guidelines
Run **writeproc test \>\> /proc/uptime**.
The proc file system implements its own **write()** function. Calling the **writeproc** command will pass input parameters to the **write()** function.
## Output<a name="section12742311179"></a>
> **NOTE**<br>
> The procfs file system does not support multi-thread access.
OHOS \# writeproc test \>\> /proc/uptime
## Note
\[INFO\]write buf is: test
Currently, the shell does not support this command.
When the system does not respond, you can use the magic key function to check whether the system is suspended by an interrupt lock (the magic key also does not respond) or view the system task running status.
When the system does not respond, you can use the magic key to check whether the system is suspended by an interrupt lock or view the system task running status.
If interrupts are responded, you can use the magic key to check the task CPU usage (**cpup**) and find out the task with the highest CPU usage. Generally, the task with a higher priority preempts the CPU resources.
If interrupts are responded, you can use the magic key to check the task CPU percent (CPUP) and locate the task with the highest CPUP. Generally, the task with a higher priority preempts the CPU resources.
## How to Use
## How to Configure
1. Configure the macro **LOSCFG_ENABLE_MAGICKEY**.
The magic key depends on the macro **LOSCFG_ENABLE_MAGICKEY**.
The magic key depends on the **LOSCFG_ENABLE_MAGICKEY** macro. Before using the magic key, select **Enable MAGIC KEY** (**Debug** ---> **Enable MAGIC KEY**) on **menuconfig**. The magic key cannot be used if this option is disabled.
1. Run the **make menuconfig** command in **kernel/liteos_a**.
>
2. Locate the **Debug** option and select **Enable MAGIC KEY**.
> On **menuconfig**, you can move the cursor to **LOSCFG_ENABLE_MAGICKEY** and enter a question mark (?) to view help Information.
This option is selected by default. If it is not selected, the magic key is invalid.
2. Press **Ctrl+R** to enable the magic key.
> **NOTE**<br>
> On **menuconfig**, you can move the cursor to **LOSCFG_ENABLE_MAGICKEY** and enter a question mark (?) to view help information.
## How to Use
1. Press **Ctrl+R** to enable the magic key.
When the UART or USB-to-virtual serial port is connected, press **Ctrl+R**. If "Magic key on" is displayed, the magic key is enabled. To disable it, press **Ctrl+R** again. If "Magic key off" is displayed, the magic key is disabled.
When the UART or USB-to-virtual serial port is connected, press **Ctrl+R**. If "Magic key on" is displayed, the magic key is enabled. To disable it, press **Ctrl+R** again. If "Magic key off" is displayed, the magic key is disabled.
The functions of the magic key are as follows:
The functions of the magic key are as follows:
...
@@ -32,5 +38,5 @@ If interrupts are responded, you can use the magic key to check the task CPU usa
...
@@ -32,5 +38,5 @@ If interrupts are responded, you can use the magic key to check the task CPU usa
-**Ctrl+E**: Checks the integrity of the memory pool. If an error is detected, the system displays an error message. If no error is detected, the system displays "system memcheck over, all passed!".
-**Ctrl+E**: Checks the integrity of the memory pool. If an error is detected, the system displays an error message. If no error is detected, the system displays "system memcheck over, all passed!".
> If magic key is enabled, when special characters need to be entered through the UART or USB-to-virtual serial port, avoid using characters the same as the magic keys. Otherwise, the magic key may be triggered by mistake, causing errors in the original design.
> If magic key is enabled, when special characters need to be entered through the UART or USB-to-virtual serial port, avoid using characters the same as the magic keys. Otherwise, the magic key may be triggered by mistake, causing errors in design.
Hosts on an Ethernet communicate with each other using MAC addresses. IP addresses must be converted into MAC addresses to enable communication between hosts on a LAN \(Ethernet\). To achieve this purpose, the host stores a table containing the mapping between IP addresses and MAC addresses. This table is called an Address Resolution Protocol \(ARP\) cache table. Before sending an IP packet to a LAN, the host looks up the destination MAC address in the ARP cache table. The ARP cache table is maintained by the TCP/IP stack. You can run the **arp** command to view and modify the ARP cache table.
Hosts on an Ethernet communicate with each other using MAC addresses. IP addresses must be converted into MAC addresses to enable communication between hosts on a LAN (Ethernet). To achieve this purpose, the host stores a table containing the mapping between IP addresses and MAC addresses. This table is called an Address Resolution Protocol (ARP) cache table. Before sending an IP packet to a LAN, the host looks up the destination MAC address in the ARP cache table. The ARP cache table is maintained by the TCP/IP stack. You can run the **arp** command to view and modify the ARP cache table.
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p1862mcpsimp"><aname="p1862mcpsimp"></a><aname="p1862mcpsimp"></a>Queries the content of the ARP cache table.</p>
- The **arp** command is used to query and modify the ARP cache table of the TCP/IP stack. If ARP entries for IP addresses on different subnets are added, the protocol stack returns a failure message.
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p1869mcpsimp"><aname="p1869mcpsimp"></a><aname="p1869mcpsimp"></a>Specifies the network port. This parameter is optional.</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p1877mcpsimp"><aname="p1877mcpsimp"></a><aname="p1877mcpsimp"></a>Adds an ARP entry. The second parameter is the IP address and MAC address of the other host on the LAN.</p>
<tdclass="cellrowborder"valign="top"width="52.16%"headers="mcps1.2.4.1.2 "><pid="p1884mcpsimp"><aname="p1884mcpsimp"></a><aname="p1884mcpsimp"></a>Deletes an ARP entry.</p>
- The **arp** command is used to query and modify the ARP cache table of the TCP/IP stack. If ARP entries for IP addresses on different subnets are added, the protocol stack returns a failure message.
- This command can be used only after the TCP/IP stack is enabled.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1915mcpsimp"><aname="p1915mcpsimp"></a><aname="p1915mcpsimp"></a>IPv4 address of a network device.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1920mcpsimp"><aname="p1920mcpsimp"></a><aname="p1920mcpsimp"></a>MAC address of a network device.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1925mcpsimp"><aname="p1925mcpsimp"></a><aname="p1925mcpsimp"></a>Name of the port used by the ARP entry.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1930mcpsimp"><aname="p1930mcpsimp"></a><aname="p1930mcpsimp"></a>Indicates whether the ARP entry is dynamic or static. A dynamic ARP entry is automatically created by the protocol stack, and a static ARP entry is added by the user.</p>
</td>
</tr>
</tbody>
</table>
| Parameter| Description|
| -------- | -------- |
| Address | IPv4 address of the network device.|
| HWaddress | MAC address of the network device.|
| Iface | Name of the port used by the ARP entry.|
| Type | Whether the ARP entry is dynamic or static. A dynamic ARP entry is automatically created by the protocol stack, and a static ARP entry is added by the user. |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p14803132214716"><aname="p14803132214716"></a><aname="p14803132214716"></a>Displays parameters supported by the <strongid="b71961312874"><aname="b71961312874"></a><aname="b71961312874"></a>dhclient</strong> command and their usage.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1180318222710"><aname="p1180318222710"></a><aname="p1180318222710"></a>Disables DHCP for a NIC.</p>
| No parameter| Displays all NIC information, which includes the IP address, network mask, gateway, MAC address, maximum transmission unit (MTUs), and running status of each NIC.| N/A |
| -a | Displays data sent and received by the protocol stack.| N/A |
</td>
| interface | Specifies the NIC name, for example, **eth0**.| N/A |
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p1594124175315"><aname="p1594124175315"></a><aname="p1594124175315"></a>Displays all NIC information, which includes the IP address, network mask, gateway, MAC address, maximum transmission unit (MTUs), and running status of each NIC.</p>
| address | Specifies the IP address, for example, **192.168.1.10**. The NIC name must be specified.| N/A |
</td>
| netmask | Specifies the subnet mask, for example, **255.255.255.0**.| N/A |
| add | Specifies the IPv6 address, for example, **2001:a:b:c:d:e:f:d**. The NIC name and **inet6** must be specified.| N/A |
</td>
| del | Deletes an IPv6 address. You need to specify the NIC name and add the **inet6** option. For details, see the example.| N/A |
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p13941445534"><aname="p13941445534"></a><aname="p13941445534"></a>Displays data sent and received by the protocol stack.</p>
| up | Enables the data processing function of the NIC. The NIC name must be specified.| N/A |
</td>
| down | Disables the data processing function of the NIC. The NIC name must be specified.| N/A |
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p139415485312"><aname="p139415485312"></a><aname="p139415485312"></a>Specifies the NIC name, for example, <strongid="b1368975571410"><aname="b1368975571410"></a><aname="b1368975571410"></a>eth0</strong>.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p119454165313"><aname="p119454165313"></a><aname="p119454165313"></a>Specifies the IP address, for example, <strongid="b530715731519"><aname="b530715731519"></a><aname="b530715731519"></a>192.168.1.10</strong>. The NIC name must be specified.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p194749536"><aname="p194749536"></a><aname="p194749536"></a>Specifies the subnet mask, for example, <strongid="b1625513191514"><aname="b1625513191514"></a><aname="b1625513191514"></a>255.255.255.0</strong>.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p109413413534"><aname="p109413413534"></a><aname="p109413413534"></a>Specifies the gateway, for example, <strongid="b52931945195112"><aname="b52931945195112"></a><aname="b52931945195112"></a>192.168.1.1</strong>.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p20946412532"><aname="p20946412532"></a><aname="p20946412532"></a>Specifies the MAC address, for example, <strongid="b85669109525"><aname="b85669109525"></a><aname="b85669109525"></a>00:11:22:33:44:55</strong>. Currently, only the <strongid="b534492414613"><aname="b534492414613"></a><aname="b534492414613"></a>ether</strong> hardware type is supported.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p159418414536"><aname="p159418414536"></a><aname="p159418414536"></a>Specifies the MTU size, for example, <strongid="b2852192012261"><aname="b2852192012261"></a><aname="b2852192012261"></a>1000</strong>.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p1952046539"><aname="p1952046539"></a><aname="p1952046539"></a>Specifies the IPv6 address, for example, <strongid="b12509153516279"><aname="b12509153516279"></a><aname="b12509153516279"></a>2001:a:b:c:d:e:f:d</strong>. The NIC name and <strongid="b912123842916"><aname="b912123842916"></a><aname="b912123842916"></a>inet6</strong> must be specified.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p1556618562119"><aname="p1556618562119"></a><aname="p1556618562119"></a>Deletes an IPv6 address. You need to specify the NIC name and add the <strongid="b166212197409"><aname="b166212197409"></a><aname="b166212197409"></a>inet6</strong> option. For details, see the example.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p119510455314"><aname="p119510455314"></a><aname="p119510455314"></a>Enables the data processing function of the NIC. The NIC name must be specified.</p>
<tdclass="cellrowborder"valign="top"width="53.669999999999995%"headers="mcps1.2.4.1.2 "><pid="p1795164105312"><aname="p1795164105312"></a><aname="p1795164105312"></a>Disables the data processing function of the NIC. The NIC name must be specified.</p>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p281516205410"><a name="p281516205410"></a><a name="p281516205410"></a>Indicates whether the NIC is running.</p>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p881516145415"><a name="p881516145415"></a><a name="p881516145415"></a>Indicates that the NIC is connected to the default gateway.</p>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18201614546"><a name="p18201614546"></a><a name="p18201614546"></a>Connection status of the NIC</p>
</td>
</tr>
</tbody>
</table>
- Example 2: obtaining protocol stack statistics
```
OHOS # ifconfig -a
RX packets:6922 errors:0 ip dropped:4312 link dropped:67 overrun:0 bytes:0 (0.0 B)
RX packets(ip6):3 errors:0 dropped:0 overrun:0 bytes:0 (0.0 B)
TX packets:1394 errors:0 link dropped:67 overrun:0 bytes:0(0.0 B)
TX packets(ip6):3 errors:0 overrun:0 bytes:0(0.0 B)
```
The following table describes the output parameters.
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p1174183145516"><a name="p1174183145516"></a><a name="p1174183145516"></a>Number of normal packets received at the IP layer.</p>
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p1274133195513"><a name="p1274133195513"></a><a name="p1274133195513"></a>Number of error packets received at the IP layer. The errors include the length error, verification error, IP option error, and IP header protocol error.</p>
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p13741637551"><a name="p13741637551"></a><a name="p13741637551"></a>Number of packets discarded at the IP layer. Packets are discarded due to packet errors, packet forwarding failures, and disabled local NICs.</p>
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p17742305517"><a name="p17742305517"></a><a name="p17742305517"></a>Number of packets that the MAC layer fails to deliver to the upper-layer protocol stack. The failure is caused by resource insufficiency at the protocol stack.</p>
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p9741385519"><a name="p9741385519"></a><a name="p9741385519"></a>Total length of normal packets received at the IP layer, excluding the length of the fragments that are not reassembled.</p>
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p19745375513"><a name="p19745375513"></a><a name="p19745375513"></a>Number of packets that have been normally sent or forwarded at the IP layer.</p>
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p9756312553"><a name="p9756312553"></a><a name="p9756312553"></a>Number of packets that the IP layer fails to send. Packets may fail to be sent because the packets cannot be routed or the packets fail to be processed in the protocol stack.</p>
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p87519395520"><a name="p87519395520"></a><a name="p87519395520"></a>Number of packets that the MAC layer discards due to delivery failures, for example, the NIC driver fails to process the packets.</p>
<td class="cellrowborder" valign="top" width="71%" headers="mcps1.2.3.1.2 "><p id="p7759375512"><a name="p7759375512"></a><a name="p7759375512"></a>Total length of the packets successfully sent or forwarded at the IP layer.</p>
HWaddr 00:49:cb:6c:a1:31 MTU:1500 Running Default Link UP
```
**Table 2** Parameter description
| Parameter| Description|
| -------- | -------- |
| ip | IP address of the board.|
| netmask | Subnet mask.|
| gateway | Gateway.|
| HWaddr | MAC address of the board.|
| MTU | Maximum transmission unit.|
| Running/Stop | Whether the NIC is running.|
| Default | Indicates that the NIC is connected to the default gateway.|
| Link UP/Down | Connection status of the NIC.|
- Example 2: Obtain protocol stack statistics.
```
OHOS # ifconfig -a
RX packets:6922 errors:0 ip dropped:4312 link dropped:67 overrun:0 bytes:0 (0.0 B)
RX packets(ip6):3 errors:0 dropped:0 overrun:0 bytes:0 (0.0 B)
TX packets:1394 errors:0 link dropped:67 overrun:0 bytes:0(0.0 B)
TX packets(ip6):3 errors:0 overrun:0 bytes:0(0.0 B)
```
**Table 3** ifconfig -a parameter description
| Parameter| Description|
| -------- | -------- |
| RX packets | Number of normal packets received at the IP layer.|
| RX error | Number of error packets received at the IP layer. The errors include the length error, verification error, IP option error, and IP header protocol error.|
| RX dropped | Number of packets discarded at the IP layer. Packets are discarded due to packet errors, packet forwarding failures, and disabled local NICs.|
| RX overrun | Number of packets that the MAC layer fails to deliver to the upper-layer protocol stack. The failure is caused by resource insufficiency at the protocol stack.|
| RX bytes | Total length of normal packets received at the IP layer, excluding the length of the fragments that are not reassembled.|
| TX packets | Number of packets that have been normally sent or forwarded at the IP layer.|
| TX error | Number of packets that the IP layer fails to send. Packets may fail to be sent because the packets cannot be routed or the packets fail to be processed in the protocol stack.|
| TX dropped | Number of packets that the MAC layer discards due to delivery failures, for example, the NIC driver fails to process the packets.|
| TX overrun | Not used currently.|
| TX bytes | Total length of the packets successfully sent or forwarded at the IP layer.|
**ipdebug**is a console command and is used for IPv6 debugging. It can display IPv6 address prefixes, neighbor entries, destination entries, and default route entries.
**ipdebug** is a console command and is used for IPv6 debugging. It can display IPv6 address prefixes, neighbor entries, destination entries, and default route entries.
## Syntax<a name="section124061758123713"></a>
## Syntax
ipdebug
ipdebug
## Example<a name="section171837113810"></a>
Run the **ipdebug** command.
## Example
Run the **ipdebug** command.
## Output<a name="section561416467104"></a>
**ipdebug** command output:
## Output
**ipdebug** command output:
```
```
OHOS # ipdebug
OHOS # ipdebug
...
@@ -52,4 +55,3 @@ FE80::4639:C4FF:FE94:5D44 FE80::4639:C4FF:FE94:5D44 pmtu 1500 age 6
...
@@ -52,4 +55,3 @@ FE80::4639:C4FF:FE94:5D44 FE80::4639:C4FF:FE94:5D44 pmtu 1500 age 6
The **netstat** command is a console command and is used for monitoring the TCP/IP network. It can display the actual network connections and the status of each network interface device. This command displays statistics related to TCP and UDP and can be used to check the network connection to each port on the device \(board\).
The **netstat** command is a console command and is used for monitoring the TCP/IP network. It can display the actual network connections and the status of each network interface device. This command displays statistics related to TCP and UDP connections and can be used to check the network connection to each port on a device (board).
## Syntax<a name="section795712373812"></a>
## Syntax
netstat
netstat
## Parameters<a name="section17629431193817"></a>
None
## Parameters
## Usage<a name="section5277153519380"></a>
None.
netstat
## Example<a name="section108141437163820"></a>
## Usage Guidelines
None.
## Note
Run **netstat**.
Currently, the shell does not support this command.
| Recv-Q | Amount of data that is not read by the user.<br>For Listen TCP, the value indicates the number of TCP connections that have finished the three-way handshake but are not accepted by users. |
</th>
| Send-Q | For a TCP connection, this value indicates the amount of data that has been sent but not acknowledged.<br>For a UDP connection, this value indicates the amount of data buffered before IP address resolution is complete.|
</tr>
| Local Address | Local IP address and port number. |
</thead>
| Foreign Address | Remote IP address and port number. |
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p2550mcpsimp"><aname="p2550mcpsimp"></a><aname="p2550mcpsimp"></a>Amount of data that is not read by the user.</p>
<pid="p2551mcpsimp"><aname="p2551mcpsimp"></a><aname="p2551mcpsimp"></a>For Listen TCP, the value indicates the number of TCP connections that have finished three-way handshake but are not accepted by users.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p1250715415473"><aname="p1250715415473"></a><aname="p1250715415473"></a>For a TCP connection, this value indicates the amount of data that has been sent but not acknowledged.</p>
<pid="p1080412214470"><aname="p1080412214470"></a><aname="p1080412214470"></a>For a UDP connection, this value indicates the amount of data buffered before IP address resolution is complete.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p2562mcpsimp"><aname="p2562mcpsimp"></a><aname="p2562mcpsimp"></a>Local IP address and port number.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p2567mcpsimp"><aname="p2567mcpsimp"></a><aname="p2567mcpsimp"></a>Remote IP address and port number.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p2572mcpsimp"><aname="p2572mcpsimp"></a><aname="p2572mcpsimp"></a>TCP connection status. This parameter is meaningless for UDP.</p>
>The command output like "========== total sockets 32 ====== unused sockets 22 BootTime 27 s ==========" indicates that there are 32 sockets in total, 22 sockets are not used, and it has been 27 seconds since the system starts.
> **NOTE**<br>
> The command output like "========== total sockets 32 ====== unused sockets 22 BootTime 27 s ==========" indicates that there are 32 sockets in total, 22 sockets are not used, and it has been 27 seconds since the system starts.
<tdclass="cellrowborder"valign="top"width="52.480000000000004%"headers="mcps1.2.4.1.2 "><pid="p2633mcpsimp"><aname="p2633mcpsimp"></a><aname="p2633mcpsimp"></a>Specifies the IP address of the NTP server.</p>
Run the **ntpdate **\[_SERVER\_IP1_\]\[_SERVER\_IP2_\]... command. **ntpdate** obtains and displays the time of the first server with a valid IP address.
| Parameter| Description| Value Range|
| -------- | -------- | -------- |
| SERVER_IP | Specifies the IP address of the NTP server.| N/A |
## Example<a name="section3431554203811"></a>
Run **ntpdate 192.168.1.3 **to update the system time.
## Usage Guidelines
Run the **ntpdate [_SERVER_IP1_] [_SERVER_IP2_]...** command to obtain and display the time of the first server with a valid IP address.
## Example
Run **ntpdate 192.168.1.3 **to update the system time.
## Output
## Output<a name="section18638194610115"></a>
```
```
OHOS # ntpdate 192.168.1.3
OHOS # ntpdate 192.168.1.3
time server 192.168.1.3: Mon Jun 13 09:24:25 2016
time server 192.168.1.3: Mon Jun 13 09:24:25 2016
```
```
If the time zone of the board is different from that of the server, the displayed time may be several hours different from the obtained server time.
If the time zone of the board is different from that of the server, the displayed time may be several hours different from the server time obtained.
| -q | Implicitly pings an IPv4 address. If the host is still alive, the ping stops after **true** is returned.| N/A |
</td>
| -s SIZE | Specifies the size of a ping packet, in bytes. The default size is **56** bytes.| 0-4088 |
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p122810445818"><aname="p122810445818"></a><aname="p122810445818"></a>Displays the parameters supported by the <strongid="b1796144112279"><aname="b1796144112279"></a><aname="b1796144112279"></a>ping</strong> command.</p>
| IP | Specifies the IPv4 address of the network to test.| N/A |
- The **ping** command is used to check whether the destination IP address is reachable.
</td>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p16281846585"><aname="p16281846585"></a><aname="p16281846585"></a>Forcibly pings the destination address using the IPv4 protocol.</p>
- If the destination IP address is unreachable, the system displays a message indicating that the request times out.
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p1281248583"><aname="p1281248583"></a><aname="p1281248583"></a>Specifies the number of execution times. The default value is <strongid="b209506262288"><aname="b209506262288"></a><aname="b209506262288"></a>3</strong>.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p22811642583"><aname="p22811642583"></a><aname="p22811642583"></a>Pings an IPv4 address in implicit mode. The default parameter configuration is equivalent to <strongid="b12261222102915"><aname="b12261222102915"></a><aname="b12261222102915"></a>-c 15 -i 0.2</strong>.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p15281184125813"><aname="p15281184125813"></a><aname="p15281184125813"></a>Specifies the interval (in ms) for sending a ping packet.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p13281124155815"><aname="p13281124155815"></a><aname="p13281124155815"></a>Implicitly pings an IPv4 address. If the host is active, the ping stops after <strongid="b3813112783011"><aname="b3813112783011"></a><aname="b3813112783011"></a>true</strong> is received.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p12281154165819"><aname="p12281154165819"></a><aname="p12281154165819"></a>Specifies the size of a ping packet, in bytes. The default size is <strongid="b145002224316"><aname="b145002224316"></a><aname="b145002224316"></a>56</strong> bytes.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p4282545588"><aname="p4282545588"></a><aname="p4282545588"></a>Specifies the IPv4 address to test.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p2759mcpsimp"><aname="p2759mcpsimp"></a><aname="p2759mcpsimp"></a>Specifies the number of execution times. If this parameter is not specified, the default value is <strongid="b1769545815488"><aname="b1769545815488"></a><aname="b1769545815488"></a>4</strong>.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p2766mcpsimp"><aname="p2766mcpsimp"></a><aname="p2766mcpsimp"></a>Performs an IPv6 ping operation for a specified NIC.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p134111362417"><aname="p134111362417"></a><aname="p134111362417"></a>Specifies the IP address of the destination host.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p2861mcpsimp"><aname="p2861mcpsimp"></a><aname="p2861mcpsimp"></a>Enables the Telnet server service.</p>
<tdclass="cellrowborder"valign="top"width="52%"headers="mcps1.2.4.1.2 "><pid="p2868mcpsimp"><aname="p2868mcpsimp"></a><aname="p2868mcpsimp"></a>Disables the Telnet server service.</p>
- Before enabling Telnet, ensure that the network driver and network protocol stack have been initialized and the NIC of the board is in the **link up** state.
| Parameter| Description| Value Range|
- Currently, multiple clients \(Telnet + IP\) cannot connect to the development board at the same time.
| -------- | -------- | -------- |
| on | Enables the telnet server service.| N/A |
| off | Disables the telnet server service.| N/A |
>Telnet is used for debugging and is disabled by default. Do not use it in formal products.
## Usage Guidelines
## Example<a name="section1097414426398"></a>
- Before enabling Telnet, ensure that the network driver and network protocol stack have been initialized and the NIC of the board is in the **link up** state.
Run **telnet on**.
- Currently, multiple clients (Telnet + IP) cannot connect to the development board at the same time.
> **NOTICE**<br>
> Telnet is used for debugging and is disabled by default. Do not use it in formal products.
## Output<a name="section11846624191310"></a>
## Example
Run **telnet on**.
## Output
Command output:
Command output:
```
```
OHOS # telnet on
OHOS # telnet on
OHOS # start telnet server successfully, waiting for connection.
OHOS # start telnet server successfully, waiting for connection.
Trivial File Transfer Protocol \(TFTP\) is a protocol in the TCP/IP protocol suite for transferring files between clients and servers. TFTP provides simple and low-overhead file transfer services. The port number is 69.
Trivial File Transfer Protocol (TFTP) is a protocol in the TCP/IP protocol suite for transferring files between clients and servers. TFTP provides simple and low-overhead file transfer services. The port number is 69.
The **tftp** command is used to transfer files with a TFTP server.
The **tftp** command is used to transfer files with a TFTP server.
| -g/-p | Specifies the file transfer direction.<br>- **-g**: obtains a file from the TFTP server.<br>- **-p**: uploads a file to the TFTP server.| N/A |
<tdclass="cellrowborder"valign="top"width="52.480000000000004%"headers="mcps1.2.4.1.2 "><pid="p2911mcpsimp"><aname="p2911mcpsimp"></a><aname="p2911mcpsimp"></a>Specifies the file transfer direction.</p>
<aname="ul73571240131312"></a><aname="ul73571240131312"></a><ulid="ul73571240131312"><li><strongid="b0778214125818"><aname="b0778214125818"></a><aname="b0778214125818"></a>-g</strong>: downloads files from the TFTP server.</li><li><strongid="b7168132555814"><aname="b7168132555814"></a><aname="b7168132555814"></a>-p</strong>: uploads files to the TFTP server.</li></ul>
1. Deploy a TFTP server on the server and configure the TFTP server correctly.
> TFTP is used for debugging and disabled by default. Do not use it in formal products.
<tdclass="cellrowborder"valign="top"width="52.480000000000004%"headers="mcps1.2.4.1.2 "><pid="p2925mcpsimp"><aname="p2925mcpsimp"></a><aname="p2925mcpsimp"></a>Specifies the complete path of a local file.</p>
<tdclass="cellrowborder"valign="top"width="52.480000000000004%"headers="mcps1.2.4.1.2 "><pid="p2931mcpsimp"><aname="p2931mcpsimp"></a><aname="p2931mcpsimp"></a>Specifies the file name on the server.</p>
<tdclass="cellrowborder"valign="top"width="52.480000000000004%"headers="mcps1.2.4.1.2 "><pid="p2937mcpsimp"><aname="p2937mcpsimp"></a><aname="p2937mcpsimp"></a>Specifies the server IP address.</p>
>TFTP is used for debugging and disabled by default. Do not use it in formal products.
## Example<a name="section148921918114015"></a>
Download the **out** file from the server.
## Output<a name="section7872155631313"></a>
```
```
OHOS # ./bin/tftp -g -l /nfs/out -r out 192.168.1.2
OHOS # ./bin/tftp -g -l /nfs/out -r out 192.168.1.2
TFTP transfer finish
TFTP transfer finish
```
```
After the **tftp** command is executed, **TFTP transfer finish** is displayed if the file transfer is complete. If the file transfer fails, other information is displayed to help locate the fault.
After the **tftp** command is executed, **TFTP transfer finish** is displayed if the file transfer is complete. If the file transfer fails, other information is displayed to help locate the fault.