process
Extensions to process object.处理对象的扩展。
Electron's Electron的process
object is extended from the Node.js process
object. process
对象是从Node.js process
对象扩展而来的。It adds the following events, properties, and methods:它添加了以下事件、属性和方法:
Sandbox
In sandboxed renderers the 在沙盒渲染器中,process
object contains only a subset of the APIs:process
对象只包含API的一个子集:
crash()
hang()
getCreationTime()
getHeapStatistics()
getBlinkMemoryInfo()
getProcessMemoryInfo()
getSystemMemoryInfo()
getSystemVersion()
getCPUUsage()
getIOCounters()
uptime()
argv
execPath
env
pid
arch
platform
sandboxed
contextIsolated
type
version
versions
mas
windowsStore
contextId
Events事件
Event: 'loaded'
Emitted when Electron has loaded its internal initialization script and is beginning to load the web page or the main script.当Electron加载其内部初始化脚本并开始加载网页或主脚本时发出。
Properties属性
process.defaultApp
Readonly
A 一个boolean
. boolean
。When app is started by being passed as parameter to the default app, this property is 当应用程序作为参数传递给默认应用程序时,此属性在主进程中为true
in the main process, otherwise it is undefined
.true
,否则为undefined
。
process.isMainFrame
Readonly
A 一个boolean
, true
when the current renderer context is the "main" renderer frame. boolean
,当当前渲染器上下文为“主”渲染器帧时为true
。If you want the ID of the current frame you should use 如果您想要当前帧的ID,您应该使用webFrame.routingId
.webFrame.routingId
。
process.mas
Readonly
A 一个boolean
. boolean
。For Mac App Store build, this property is 对于Mac App Store版本,此属性为true
, for other builds it is undefined
.true
,而对于其他版本,则为undefined
。
process.noAsar
A 一个boolean
that controls ASAR support inside your application. boolean
,用于控制应用程序内部的ASAR支持。Setting this to 将此设置为true
will disable the support for asar
archives in Node's built-in modules.true
将禁用Node内置模块中对asar
存档的支持。
process.noDeprecation
A 一个boolean
that controls whether or not deprecation warnings are printed to stderr
. boolean
,用于控制是否将弃用警告打印到stderr
。Setting this to 将此设置为true
will silence deprecation warnings. true
将使弃用警告静音。This property is used instead of the 使用此属性代替--no-deprecation
command line flag.--no-deprecation
命令行标志。
process.resourcesPath
Readonly
A 一个string
representing the path to the resources directory.string
,表示资源目录的路径。
process.sandboxed
Readonly
A 一个boolean
. boolean
值。When the renderer process is sandboxed, this property is 当渲染器进程被沙盒化时,此属性为true
, otherwise it is undefined
.true
,否则为undefined
。
process.contextIsolated
Readonly
A 一个boolean
that indicates whether the current renderer context has contextIsolation
enabled. boolean
,指示当前渲染器上下文是否启用了contextIsolation
。It is 它在主进程中为undefined
in the main process.undefined
。
process.throwDeprecation
A 一个boolean
that controls whether or not deprecation warnings will be thrown as exceptions. boolean
,用于控制是否将弃用警告作为异常抛出。Setting this to 将此设置为true
will throw errors for deprecations. true
将引发用于弃用的错误。This property is used instead of the 使用此属性而不是--throw-deprecation
command line flag.--throw-deprecation
命令行标志。
process.traceDeprecation
A 一个boolean
that controls whether or not deprecations printed to stderr
include their stack trace. boolean
,用于控制打印到stderr
的弃用是否包括其堆栈跟踪。Setting this to 将此设置为true
will print stack traces for deprecations. true
将打印用于弃用的堆栈跟踪。This property is instead of the 此属性不是--trace-deprecation
command line flag.--trace-deprecation
命令行标志。
process.traceProcessWarnings
A 一个boolean
that controls whether or not process warnings printed to stderr
include their stack trace. boolean
,用于控制打印到stderr
的进程警告是否包括其堆栈跟踪。Setting this to 将此设置为true
will print stack traces for process warnings (including deprecations). true
将打印进程警告(包括弃用)的堆栈跟踪。This property is instead of the 此属性不是--trace-warnings
command line flag.--trace-warnings
命令行标志。
process.type
Readonly
A 表示当前进程类型的string
representing the current process's type, can be:string
,可以是:
browser
-The main process主要流程renderer
-A renderer process渲染器进程worker
-In a web worker在网络工作者中
process.versions.chrome
Readonly
A 表示Chrome版本字符串的string
representing Chrome's version string.string
。
process.versions.electron
Readonly
A 表示Electron版本字符串的string
representing Electron's version string.string
。
process.windowsStore
Readonly
A 一个boolean
. boolean
。If the app is running as a Windows Store app (appx), this property is 如果应用程序作为Windows应用商店应用程序(appx)运行,则此属性为true
, for otherwise it is undefined
.true
,否则为undefined
。
process.contextId
Readonly
A 一个string
(optional) representing a globally unique ID of the current JavaScript context. string
(可选),表示当前JavaScript上下文的全局唯一ID。Each frame has its own JavaScript context. 每个帧都有自己的JavaScript上下文。When contextIsolation is enabled, the isolated world also has a separate JavaScript context. 当启用contextIsolation时,隔离的世界也有一个单独的JavaScript上下文。This property is only available in the renderer process.此属性仅在渲染器进程中可用。
Methods方法
The process
object has the following methods:process
对象具有以下方法:
process.crash()
Causes the main thread of the current process crash.导致当前进程的主线程崩溃。
process.getCreationTime()
Returns返回number | null
- The number of milliseconds since epoch, or 自epoch以来的毫秒数,如果信息不可用,则为null
if the information is unavailablenull
Indicates the creation time of the application. 指示应用程序的创建时间。The time is represented as number of milliseconds since epoch. 时间表示为自epoch以来的毫秒数。It returns null if it is unable to get the process creation time.如果无法获取进程创建时间,则返回null
。
process.getCPUUsage()
Returns 返回CPUUsage
process.getIOCounters()
Windows Linux
Returns 返回IOCounters
process.getHeapStatistics()
Returns返回Object
:
totalHeapSize
IntegertotalHeapSizeExecutable
IntegertotalPhysicalSize
IntegertotalAvailableSize
IntegerusedHeapSize
IntegerheapSizeLimit
IntegermallocedMemory
IntegerpeakMallocedMemory
IntegerdoesZapGarbage
boolean
Returns an object with V8 heap statistics. 返回一个具有V8堆统计信息的对象。Note that all statistics are reported in Kilobytes.请注意,所有统计数据都以千字节为单位报告。
process.getBlinkMemoryInfo()
Returns返回Object
:
allocated
Integer -Size of all allocated objects in Kilobytes.所有已分配对象的大小(以千字节为单位)。total
Integer -Total allocated space in Kilobytes.已分配的总空间(KB)。
Returns an object with Blink memory information. 返回具有闪烁内存信息的对象。It can be useful for debugging rendering / DOM related memory issues. 它对于调试渲染/DOM相关的内存问题非常有用。Note that all values are reported in Kilobytes.请注意,所有值都以千字节为单位报告。
process.getProcessMemoryInfo()
Returns返回Promise<ProcessMemoryInfo>
- Resolves with a ProcessMemoryInfo
Returns an object giving memory usage statistics about the current process. 返回一个对象,该对象提供有关当前进程的内存使用情况统计信息。Note that all statistics are reported in Kilobytes. 请注意,所有统计数据都以千字节为单位报告。This api should be called after app ready.这个api应该在应用程序准备好之后调用。
Chromium does not provide Chromium不为macOS提供residentSet
value for macOS. residentSet
值。This is because macOS performs in-memory compression of pages that haven't been recently used. 这是因为macOS对最近没有使用过的页面执行内存压缩。As a result the resident set size value is not what one would expect. 因此,驻留集大小值不是人们所期望的。private
memory is more representative of the actual pre-compression memory usage of the process on macOS.private
内存更能代表macOS上进程的实际预压缩内存使用情况。
process.getSystemMemoryInfo()
Returns返回Object
:
total
Integer -The total amount of physical memory in Kilobytes available to the system.系统可用的物理内存总量(以千字节为单位)。free
Integer -The total amount of memory not being used by applications or disk cache.应用程序或磁盘缓存未使用的内存总量。swapTotal
Integer Windows Linux -The total amount of swap memory in Kilobytes available to the system.系统可用的交换内存总量(以千字节为单位)。swapFree
Integer Windows Linux -The free amount of swap memory in Kilobytes available to the system.系统可用的可用交换内存量(以千字节为单位)。
Returns an object giving memory usage statistics about the entire system. 返回一个对象,该对象提供有关整个系统的内存使用情况统计信息。Note that all statistics are reported in Kilobytes.请注意,所有统计数据都以千字节为单位报告。
process.getSystemVersion()
Returns返回string
- The version of the host operating system.主机操作系统的版本。
Example:示例:
const version = process.getSystemVersion()
console.log(version)
// On macOS -> '10.13.6'
// On Windows -> '10.0.17763'
// On Linux -> '4.15.0-45-generic'
Note: It returns the actual operating system version instead of kernel version on macOS unlike 它返回实际的操作系统版本,而不是macOS上的内核版本,这与os.release()
.os.release()
不同。
process.takeHeapSnapshot(filePath)
filePath
string -Path to the output file.输出文件的路径。
Returns返回boolean
- Indicates whether the snapshot has been created successfully.指示快照是否已成功创建。
Takes a V8 heap snapshot and saves it to 获取一个V8堆快照并将其保存到filePath
.filePath
中。
process.hang()
Causes the main thread of the current process hang.导致当前进程的主线程挂起。
process.setFdLimit(maxDescriptors)
macOS Linux
maxDescriptors
Integer
Sets the file descriptor soft limit to 将文件描述符软限制设置为maxDescriptors
or the OS hard limit, whichever is lower for the current process.maxDescriptors
或OS硬限制,以当前进程的较低值为准。