This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
api:process:zh [2022/08/11 10:43] fight_xing created |
api:process:zh [2023/11/29 14:33] (current) hfsr [Process(进程) API] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | Process API | + | Process(进程) API |
========== | ========== | ||
+ | 此API提供了基本的进程管理功能。 | ||
+ | 此API主要被`io`模块用于向不同程序分别提供标准输入输出。 | ||
- | **本篇文章的部分/全部内容还没有进行翻译。** | + | 将进程看作带有额外元数据的协程会有助于理解。进程会继承其父进程的元数据,同时也可以定义自己的元数据。这些元数据支持stdio和控制台屏幕。进程创建的所有协程都会像其子线程一样被分组。 |
- | + | ||
- | This API provides rudimentary process management. It is used mainly by the `io` module to provide individual standard input and output to individual programs. | + | |
- | + | ||
- | It can be helpful to think of a process as a coroutine with extra metadata. A process inherits the metadata of its parent, but can define its own. Such metadata supports stdio and terminal windows. All coroutines created are grouped like child threads of the current process. | + | |
- `process.load(path:string[, env:table[, init:function[, name:string]]]):coroutine` | - `process.load(path:string[, env:table[, init:function[, name:string]]]):coroutine` | ||
- | Loads a Lua script from the specified *absolute* `path` and sets it up as a process. | + | 从指定的**绝对路径**`path`加载一个Lua脚本,并将其作为进程运行。 |
- | It will be loaded with a custom environment, to avoid cluttering the callers/global environment. This environment will have access to anything in the specified environment, or the default (top level) environment if none is given. | + | 此进程将会被加载到一个自定义环境,以避免污染调用者或全局的环境。此环境将会获得给定环境的所有权限,若不指定则默认会给予最高权限环境。 |
- | + | (自OpenOS 1.6起)`path`也可为函数,此时`env`必须为`nil`。 | |
- | (since OpenOS 1.6) `path` can also be a function, in which case `env` must be `nil`. | + | 若给定`init`函数,则此方法会在`prosecc.load`产生的协程第一次执行时被调用,并在程序实际开始运行前执行。这可以用于微调程序运行环境。 |
- | | + | 若给定`name`参数,则`process.running`的结果中会将此进程指定为此名称。此参数也可以为`nil`。 |
- | If an `init` function is specified, that method is called the first time the resulting coroutine is executed, and run before the actual program is started. This allows fine-tuning of the programs environment. | + | \\ |
- | If a `name` is specified, that is the name the process will specify in `process.running`. It will be `nil` otherwise. | + | - `process.info([level: number]): table` |
- | - `process.info([level: number]): table` | + | 返回一个表,其中包含指定进程的命令、路径与一些其他数据。`level`参数为可选参数,若给定则可获取父进程。默认情况下此值为1,即当前进程。若为2代表当前进程的父进程(调用`process.load`启动了此进程的进程)。以此类推。 |
- | Returns a table containing the command and path of the specified process, and some other data. The `level` can optionally be provided to get parent processes. It defaults to 1, the current program. 2 is the current program's parent (the one that called `process.load` to start the current program) and so on. | + | \\ |
- | - `process.running([level: number]): string, table, string` | + | - `process.running([level: number]): string, table, string`(自1.5起弃用,改用`process.info`代替) |
- | (deprecated as of 1.5, use process.info instead) Returns the path to the currently running program (i.e. the last process created via `process.load`). The level can optionally be provided to get parent processes. It defaults to 1, the current program. 2 is the current program's parent (the one that called `process.load` to start the current program) and so on. | + | 返回指向当前运行程序(即通过`process.load`创建的最后一个进程)的路径。`level`参数为可选参数,若给定则可获取父进程。默认情况下此值为1,即当前进程。若为2代表当前进程的父进程(调用了 `process.load` 启动了此进程的进程)。以此类推。 |
- | The second returned value is the environment of the process, i.e. the table created for it to use as one. | + | 第二个返回值为进程的环境,即为了其使用而创建的表。 |
- | The third returned value is the 'name' of the process, i.e. the fourth parameter to `process.load`. For programs started via the shell this will ususally be the original command. E.g. for `ls -l`, the first returned value will be `ls`, while this value will be `ls -l`. | + | 第三个返回值为进程的`name`,即`process.load`的第四个参数。对通过shell启动的程序而言此值为启动时的原始命令。例如,对`ls -l`命令,第一个返回值为`ls`,而第三个返回值为`ls -l`。 |
目录 | 目录 | ||
----------- | ----------- | ||
{{page>api:contents:zh&noheader&noeditbutton&nouser&nofooter}} | {{page>api:contents:zh&noheader&noeditbutton&nouser&nofooter}} |