In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of POSIX standard in Node.js api, which is very detailed and has certain reference value. Friends who are interested must finish it!
If you have used Node.js 's api, will you wonder why the name api looks like this:
For example, create a directory:
Const fs = require ('fs'); fs.mkdir (' / an if bAccorder, {recursive: true}, (err) = > {if (err) throw err;})
Create the process:
Const childProcess = require ('child_process'); childProcess.fork (' a-lh',. JS'); childProcess.execFile ('a-lh','); childProcess.exec ('"/ path/to/test file/test.sh" arg1 arg2'); childProcess.spawn ('- lh','/ usr'])
Mkdir, fork, exec, spawn, etc., how do these names come from?
If you have used the linux command or the c function library, you will find that these api have the same name in both the command and c function library.
What causes it? Are these api standards?
Yes, this is the POSIX standard.
What is POSIX?
POSIX is an abbreviation for portable operating system interface (Portable operating system Interface), and x means unix, which is inherited from unix.
Because different operating systems provide different functions and system calls, then the source code of the upper-level application based on the operating system is different, which makes the code written by one platform can not be compiled on another platform.
What should I do?
What if each operating system provides the same api? No matter how the underlying operating system implements these capabilities, just expose the same api to the application, so that the source code is cross-platform and can run after compilation on different operating systems.
The standard for api exposed by this unified operating system is POSIX.
This POSIX standard can be understood as an interface defined in ts. As long as the api that implements this interface is compatible with the POSIX standard.
POSIX was first extended by unix, and linux implemented this POSIX standard. Later, windows was under pressure to be compatible with the POSIX standard, otherwise many linux applications would not be able to run on windows. So is our commonly used osx.
Therefore, POSIX is some standard interface for the operating system to provide capabilities to upper-level applications, including system calls, c function libraries, and shell commands.
The so-called standard is recognized by the ISO International Organization for Standardization, which is an international organization with members in various countries and an organization that formulates various international standards. POSIX is the ISO/IEC 9945 standard (IEC is an electronic-oriented standardization organization). In fact, POSIX was put forward by IEEE, which is an American standardization organization. The standard he proposed will be recognized as an international standard by ISO. For example, POSIX is their IEEE Std 1003 standard, which is now recognized by ISO and has become an ISO/IEC 9945 standard.
What is the content of POSIX?
Let's take a look at what system calls are provided by linux that supports posix (system calls refer to programs provided in kernel code):
Process control:
Fork creates a new process
Execv runs executable files
Exit aborts the process
File reading and writing
Open opens a file
Close closes the file descriptor
Write writes files
Read reads the file
Truncate truncated file
Fsync writes files to disk in part of memory.
File system related
Access determines whether the file is accessible
Chdir changes the current working directory
Chown changes the owner or user group of the file
Stat fetches file status information
Mkdir create directory
Symlink creates symbolic links
Unlink delete link
Etc.
Many of these system calls have commands with the same name as api,shell with the same name in Node.js:
For example:
Fs.statsfs.accessfs.chownfs.mkdirfs.openfs.closefs.readfs.writechild_process.forkchild_process.execchild_process.execFile
Etc.
Characteristics of Node.js api
Node.js is a js runtime, based on v8 to inject a lot of api that provide operating system capabilities to js calls, and many of these api designs are directly using the api name of the POSIX standard, without doing a lot of abstraction.
Java's JRE (java runtime) also provides abstraction of operating system capabilities, but those api have little to do with the api of operating system POSIX and incorporate a lot of design patterns, such as the decorator pattern of io streams.
Node.js 's api is characterized by not much abstraction, and many api names are similar to linux commands, close to the POSIX standard. So when learning Node.js, you still have to learn the linux command, and there is a certain relationship between the two in design.
The above is all the contents of the article "sample Analysis of POSIX Standards in Node.js api". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.