انتقل إلى المحتوى

process

بيانات العملية الوصفية وبيئتها وتدفقاتها ومساعدات دورة حياتها المتوافقة مع ⁦Node⁩.

في هذه الصفحة

تشير ⁦globalThis.process⁩ و⁦node:process⁩ و⁦process⁩ و⁦elide:process⁩ إلى الكائن نفسه.

خصائص ⁦Node⁩ الشائعة متاحة، بما في ذلك ⁦argv⁩ و⁦execArgv⁩ و⁦env⁩ و⁦arch⁩ و⁦platform⁩ و⁦pid⁩ و⁦ppid⁩ و⁦version⁩ و⁦versions⁩ و⁦execPath⁩ و⁦title⁩ و⁦cwd()⁩ و⁦umask()⁩ و⁦exitCode⁩ و⁦exit()⁩.

console.log(process.platform, process.arch);
console.log(process.cwd());

if (process.env.CI) process.exitCode = 1;

الأحداث والجدولة

‏⁦process⁩ من نوع ⁦EventEmitter⁩. وهو يدعم توابع المستمعين القياسية و أحداث بيئة التشغيل مثل ⁦warning⁩ و⁦beforeExit⁩ و⁦exit⁩ و ⁦uncaughtException⁩.

يعمل ⁦process.nextTick(callback, ...args)⁩ قبل استدعاءات ⁦Promise⁩ و ⁦queueMicrotask⁩ عند نقطة التحقق التالية:

const order = [];
process.nextTick(() => order.push("tick"));
Promise.resolve().then(() => order.push("promise"));
queueMicrotask(() => order.push("microtask"));
setImmediate(() => console.log(order));
// ["tick", "promise", "microtask"]

التدفقات القياسية

‏⁦stdin⁩ و⁦stdout⁩ و⁦stderr⁩ تدفقات ⁦Node⁩. ويكشف ⁦stdout⁩ و⁦stderr⁩ واصف الملف الخاص بهما عبر ⁦fd⁩؛ كما تكشف تدفقات الطرفية حقول ⁦TTY⁩. تُوجَّه مخرجات ⁦console⁩ عبر هذه التدفقات، لذا فإن استبدال ⁦process.stdout.write⁩ يعترض مخرجات ⁦console.log⁩.

البيئة

يكشف ⁦process.env⁩ البيئة المرئية ككائن قابل للتغيير. راجع متغيرات البيئة للتحميل والتعديل و سلوك العمليات الفرعية.

المقاييس الجزئية

‏⁦hrtime()⁩ و⁦cpuUsage()⁩ و⁦memoryUsage()⁩ و⁦uptime()⁩ قابلة للاستدعاء. يعيد ⁦cpuUsage()⁩ و⁦memoryUsage()⁩ كائنات فارغة، لذا لا تعتمد على حقول المقاييس التفصيلية في ⁦Node⁩. ويتوفر ⁦process.send⁩ و⁦process.disconnect⁩ في عملية ابن بُدئت باستخدام ⁦child_process.fork()⁩.

Reference

Status: Partial · 77 of 87 suite tests pass (88.5%) · since 1.1.0

Exports

ExportKindStatusNotes
process.archpropertyFullCPU architecture of the process (e.g. “x64”, “arm64”)
process.argvpropertyFullCommand-line arguments passed to the process, starting with the node executable path
process.argv0propertyFullThe original value of argv[0] before any modification by Node.js
process.envpropertyFullObject containing the process environment variables
process.execArgvpropertyFullNode.js-specific flags passed to the node executable
process.execPathpropertyFullAbsolute path of the node executable
process.pidpropertyFullProcess ID
process.ppidpropertyFullParent process ID
process.platformpropertyFullOperating system platform (e.g. “linux”, “darwin”, “win32”)
process.titlepropertyFullDisplayed process title (settable in most environments)
process.versionpropertyFullNode.js version string (e.g. “v20.0.0”)
process.versionspropertyFullObject mapping dependency names to their version strings
process.abort()functionFullTerminates the process immediately with a core dump (SIGABRT)
process.cwd()functionFullReturns the current working directory of the process
process.chdir()functionFullChanges the current working directory of the process
process.exit()functionFullTerminates the process with the given exit code
process.getuid()functionFullReturns the numeric user ID of the process owner
process.getgid()functionFullReturns the numeric group ID of the process owner
process.geteuid()functionFullReturns the effective numeric user ID
process.getegid()functionFullReturns the effective numeric group ID
process.hrtime()functionFullReturns the current high-resolution time as [seconds, nanoseconds]
process.umask()functionFullGets or sets the file creation mode mask
process.cpuUsage()functionFullReturns the CPU time used since an optional reference point
process.memoryUsage()functionFullReturns a snapshot of the current process memory usage
process.uptime()functionFullReturns the number of seconds the current process has been running
process.nextTick()functionFullSchedules a callback to run after I/O events but before timers in the current event loop tick
process.stdinpropertyFullReadable stream connected to stdin
process.stdoutpropertyFullWritable stream connected to stdout
process.stderrpropertyFullWritable stream connected to stderr

Not implemented

addUncaughtExceptionCaptureCallback, debugPort, finalization, getBuiltinModule, report, resourceUsage, sourceMapsEnabled.

Tests: node-api node:process: 77 pass, 10 fail, 0 error, 6 skipped. Failing: test-process-dlopen-error-message-crash.js, test-process-env-allowed-flags-are-documented.js, test-process-env-allowed-flags.js, test-process-exec-argv.js, test-process-execve-permission-fail.js, test-process-exit-code-validation.js, test-process-load-env-file.js, test-process-remove-all-signal-listeners.js, and 2 more.

هل كانت هذه الصفحة مفيدة؟