1 Star 0 Fork 4.9K

fish / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
differences-from-the-linux-standard-library.md 4.24 KB
一键复制 编辑 原始数据 按行查看 历史
NEEN 提交于 2021-03-12 17:59 . !197 Docs Update version 1.0.1

Differences from the Linux Standard Library

This section describes the key differences between the standard library carried by the OpenHarmony kernel and the Linux standard library. For more information, see the API document of the C library.

Process

  1. Only the static priority is supported by OpenHarmony user-level processes. The priority ranges from 10 (highest priority) to 31 (lowest priority).
  2. Only the static priority is supported by OpenHarmony user-level threads. The priority ranges from 0 (highest priority) to 31 (lowest priority).
  3. OpenHarmony process scheduling policy can only be SCHED_RR, and the thread scheduling policy can be SCHED_RR or SCHED_FIFO.

Memory

Differences from Linux mmap

mmap prototype: void *mmap (void *addr, size_t length, int prot, int flags, int fd, off_t offset)

The lifecycle implementation of fd is different from that of Linux glibc. To be specific, the glibc can release the fd handle immediately after successfully invoking the mmap for mapping. In the OpenHarmony kernel, you are not allowed to close fd immediately after the mapping is successful. You can close fd only after the munmap is canceled. If you do not close the fd, the operating system reclaims it when the process exits.

Code Example

For Linux OS:

int main(int argc, char *argv[])
{
    int fd;
    void *addr = NULL;
    ...
    fd = open(argv[1], O_RDONLY);
    if (fd == -1){
        perror("open");
        exit(EXIT_FAILURE);
    }
    addr = mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, offset);
    if (addr == MAP_FAILED) {
        perror("mmap");
        exit(EXIT_FAILURE);
    }
    close(fd); /*  OpenHarmony does not support closing fd immediately after the mapping is successful. */ 
    ...
    exit(EXIT_SUCCESS);
}

For OpenHarmony:

int main(int argc, char *argv[])
{
    int fd;
    void *addr = NULL;
    ...
    fd = open(argv[1], O_RDONLY);
    if (fd == -1) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    addr = mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, offset);
    if (addr == MAP_FAILED) {
        perror("mmap");
        exit(EXIT_FAILURE);
    }
    ...
    munmap(addr, length);
    close(fd); /* Close fd after the munmap is canceled. */
    exit(EXIT_SUCCESS);
}

File System

System directories: include /dev, /proc, /app, /bin, /data, /etc, /lib, /system and /usr. Users do not have the permission to modify the directories and mount devices.

User directory: refers to /storage. Users can create, read, and write files in this directory, but cannot mount devices.

In addition to the system and user directories, you can create folders to mount devices. Note that a mounted folder and its subfolders cannot be mounted repeatedly or in nested mode. A non-empty folder cannot be mounted.

Signal

  • The default behavior for signals does not include STOP, CONTINUE, and COREDUMP.
  • A sleeping process (for example, a process enters the sleeping status by calling the sleep function) cannot be woken up by a signal. Cause: The signal mechanism does not support wakeup. The behavior for a signal can be processed only when the process is scheduled by the CPU.
  • After a process exits, SIGCHLD is sent to its parent process. The sending action cannot be canceled.
  • Only signals 1 to 30 are supported. If the receiver receives the same signal multiple times, the callback function is executed only once.

Time

The time precision of OpenHarmony is tick, with the default value of 10 ms/tick. The discrepancy of the sleep and timeout functions is less than or equal to 2 ticks.

1
https://gitee.com/fish_neil/docs.git
git@gitee.com:fish_neil/docs.git
fish_neil
docs
docs
master

搜索帮助