Node.js进程管理之Process模块
在前面Node.js事件运行机制也有提到,Node.js应用在单个线程运行,但是现在大部分服务器都是多处理器,为了方便使用多个进程,Node.js提供了3个模块。Process模块提供了访问正在运行的进程。child_process模块可以创建子进程,并与他们通信。cluster模块提供了实现共享相同端口的集群服务能力,允许多个请求同时处理。
一、Process模块是一个无须使用require()就可以从node.js应用程序进行访问的全局对象。
二、进程I/O管道
Process为进程stdin、stdout、stderr提供了对标准I/O管道的访问。(有点了类似C++的输入输出的赶脚)
stdin输入,stdout、stderr可以实现输出
/**
* Created by Administrator on 2016/3/29.
*/
process.stdin.on('data',function(data){
process.stdout.write(data.toString());
process.stderr.write(data.toString());
});
"C:\Program Files (x86)\JetBrains\WebStorm 11.0.3\bin\runnerw.exe" F:\nodejs\node.exe Process.js
ssss
ssss
ssss
三、进程的信号
说起信号让我想起了信号量,虽然它们不是一回事,刚才也百度了下,算是复习重温一下。
我记得大学时候学操作系统的时候也有讲过信号量的问题,进程间通信访问临界值时要使用信号量什么PV操作,具体的内容了解的不是很清楚.网上找到了一个工作原理http://blog.csdn.net/ljianhui/article/details/10243617。
var util = require('util');
//返回进程的当前工作目录
console.log('Current directory: ' + process.cwd());
//该进程的环境中指定的键/值对
console.log('Environment Settings: ' + JSON.stringify(process.env));
//用于启动Node.js应用程序的命令参数
console.log('Node Args: ' + process.argv);
//Node。js从中启动的绝对路径
console.log('Execution Path: ' + process.execPath);
//用于启动应用程序的特定节点的命令行选项
console.log('Execution Args: ' + JSON.stringify(process.execArgv));
//Node.js版本号
console.log('Node Version: ' + process.version);
//提供一个对象,包含Node.js应用程序所需的模块和版本
console.log('Module Versions: ' + JSON.stringify(process.versions));
//用于编译当前节点可执行程序的配置选项
console.log('Node Config: ' + JSON.stringify(process.config));
//当前进程ID
console.log('Process ID: ' + process.pid);
//当前进程标题
console.log('Process Title: ' + process.title);
//操作系统
console.log('Process Platform: ' + process.platform);
//进程正在运行的处理器体系结构
console.log('Process Architecture: ' + process.arch);
//Node.js进程的当前内存使用情况可使用util.inspect()读取
console.log('Memory Usage: ' + util.inspect(process.memoryUsage()));
//返回一个高精确的时间
var start = process.hrtime();
setTimeout(function() {
var delta = process.hrtime(start);
console.log('High-Res timer took %d seconds and %d nanoseconds',
delta[0], + delta[1]);
console.log('Node has been running %d seconds', process.uptime());
}, 1000);
"C:\Program Files (x86)\JetBrains\WebStorm 11.0.3\bin\runnerw.exe" F:\nodejs\node.exe process_info.js
Current directory: c:\Users\Administrator\Desktop\nodejs-mongodb-angularjs-web-development-master\ch09
Environment Settings: {"#envTSLOGTSLOG11328":"100839136","ALLUSERSPROFILE":"C:\\ProgramData","APPDATA":"C:\\Users\\Administrator\\AppData\\Roaming","asl.log":"Destination=file","CommonProgramFiles":"C:\\Program Files\\Common Files","CommonProgramFiles(x86)":"C:\\Program Files (x86)\\Common Files","CommonProgramW6432":"C:\\Program Files\\Common Files","COMPUTERNAME":"LENOVO-PC","ComSpec":"C:\\WINDOWS\\system32\\cmd.exe","configsetroot":"C:\\WINDOWS\\ConfigSetRoot","FPS_BROWSER_APP_PROFILE_STRING":"Internet Explorer","FPS_BROWSER_USER_PROFILE_STRING":"Default","FP_NO_HOST_CHECK":"NO","HOMEDRIVE":"C:","HOMEPATH":"\\Users\\Administrator","LOCALAPPDATA":"C:\\Users\\Administrator\\AppData\\Local","LOGONSERVER":"\\\\MicrosoftAccount","NUMBER_OF_PROCESSORS":"4","OS":"Windows_NT","Path":"C:\\PROGRAM FILES (X86)\\INTEL\\ICLS CLIENT\\;C:\\PROGRAM FILES\\INTEL\\ICLS CLIENT\\;C:\\WINDOWS\\SYSTEM32;C:\\WINDOWS;C:\\WINDOWS\\SYSTEM32\\WBEM;C:\\WINDOWS\\SYSTEM32\\WINDOWSPOWERSHELL\\V1.0\\;C:\\PROGRAM FILES\\INTEL\\INTEL(R) MANAGEMENT ENGINE COMPONENTS\\DAL;C:\\PROGRAM FILES\\INTEL\\INTEL(R) MANAGEMENT ENGINE COMPONENTS\\IPT;C:\\PROGRAM FILES (X86)\\INTEL\\INTEL(R) MANAGEMENT ENGINE COMPONENTS\\DAL;C:\\PROGRAM FILES (X86)\\INTEL\\INTEL(R) MANAGEMENT ENGINE COMPONENTS\\IPT;C:\\PROGRAM FILES (X86)\\ATI TECHNOLOGIES\\ATI.ACE\\CORE-STATIC;;C:\\WINDOWS\\SYSTEM32;C:\\WINDOWS;C:\\WINDOWS\\SYSTEM32\\WBEM;C:\\WINDOWS\\SYSTEM32\\WINDOWSPOWERSHELL\\V1.0\\;C:\\PROGRAM FILES (X86)\\AMD\\ATI.ACE\\CORE-STATIC;C:\\Program Files\\Lenovo\\Bluetooth Software\\;C:\\Program Files\\Lenovo\\Bluetooth Software\\syswow64;F:\\nodejs\\;C:\\WINDOWS\\system32\\config\\systemprofile\\.dnx\\bin;C:\\Program Files\\Microsoft DNX\\Dnvm\\;C:\\Program Files (x86)\\Lenovo\\Lenovo Home\\DCMainWin.exe;C:\\Users\\Administrator\\AppData\\Roaming\\npm","PATHEXT":".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC","PROCESSOR_ARCHITECTURE":"AMD64","PROCESSOR_IDENTIFIER":"Intel64 Family 6 Model 60 Stepping 3, GenuineIntel","PROCESSOR_LEVEL":"6","PROCESSOR_REVISION":"3c03","ProgramData":"C:\\ProgramData","ProgramFiles":"C:\\Program Files","ProgramFiles(x86)":"C:\\Program Files (x86)","ProgramW6432":"C:\\Program Files","PSModulePath":"C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\","PUBLIC":"C:\\Users\\Public","SESSIONNAME":"Console","SystemDrive":"C:","SystemRoot":"C:\\WINDOWS","TEMP":"C:\\Users\\ADMINI~1\\AppData\\Local\\Temp","TMP":"C:\\Users\\ADMINI~1\\AppData\\Local\\Temp","USERDOMAIN":"LENOVO-PC","USERDOMAIN_ROAMINGPROFILE":"LENOVO-PC","USERNAME":"Administrator","USERPROFILE":"C:\\Users\\Administrator","VS140COMNTOOLS":"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\","windir":"C:\\WINDOWS"}
Node Args: F:\nodejs\node.exe,c:\Users\Administrator\Desktop\nodejs-mongodb-angularjs-web-development-master\ch09\process_info.js
Execution Path: F:\nodejs\node.exe
Execution Args: []
Node Version: v4.3.2
Module Versions: {"http_parser":"2.5.2","node":"4.3.2","v8":"4.5.103.35","uv":"1.8.0","zlib":"1.2.8","ares":"1.10.1-DEV","icu":"56.1","modules":"46","openssl":"1.0.2g"}
Node Config: {"target_defaults":{"cflags":[],"default_configuration":"Release","defines":[],"include_dirs":[],"libraries":[]},"variables":{"asan":0,"host_arch":"x64","icu_data_file":"icudt56l.dat","icu_data_in":"../../deps/icu/source/data/in\\icudt56l.dat","icu_endianness":"l","icu_gyp_path":"tools/icu/icu-generic.gyp","icu_locales":"en,root","icu_path":"deps\\icu","icu_small":true,"icu_ver_major":"56","node_byteorder":"little","node_install_npm":true,"node_prefix":"/usr/local","node_release_urlbase":"","node_shared_http_parser":false,"node_shared_libuv":false,"node_shared_openssl":false,"node_shared_zlib":false,"node_tag":"","node_use_dtrace":false,"node_use_etw":true,"node_use_lttng":false,"node_use_openssl":true,"node_use_perfctr":true,"openssl_fips":"","openssl_no_asm":0,"python":"C:\\Python27\\python.exe","target_arch":"x64","v8_enable_gdbjit":0,"v8_enable_i18n_support":1,"v8_no_strict_aliasing":1,"v8_optimized_debug":0,"v8_random_seed":0,"v8_use_snapshot":true,"want_separate_host_toolset":0}}
Process ID: 8124
Process Title: C:\Program Files (x86)\JetBrains\WebStorm 11.0.3\bin\runnerw.exe
Process Platform: win32
Process Architecture: x64
Memory Usage: { rss: 17641472, heapTotal: 7409232, heapUsed: 3756584 }
High-Res timer took 1 seconds and 107153 nanoseconds
Node has been running 1.128 seconds Process finished with exit code 0
Node.js进程管理之Process模块的更多相关文章
- Node.js进程管理之子进程
一.理论 之前看多进程这一章节时发现这块东西挺多,写Process模块的时候也有提到,今天下午午休醒来静下心来好好的看了一遍,发现也不是太难理解. Node.js是单线程的,对于现在普遍是多处理器的机 ...
- Node.js进程管理之进程集群
一.cluster模块 Node.js是单线程处理,对于高并发的请求怎么样能增加吞吐量呢?为了提高服务器的利用率,能不能多核的来处理呢?于是就有了cluster模块. cluster模块可以轻松实现运 ...
- 极简 Node.js 入门 - 2.3 process
极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...
- Process Node.js 进程
Process 进程 process.argv 是命令行参数数组,第一个元素是node,第二个元素是脚本文件名,从第三个元素开始每个元素是一个运行参数. process.stdout 标准输出流 co ...
- Node.js进程通信模块child_process
前言 Node.js是一种单线程的编程模型,对Node.js的赞美和诟病的也都是因为它的单线程模型,所有的任务都在一个线程中完成(I/O等例外).单线程模型,不仅让代码非常简洁,更是直接避免了线程调度 ...
- 深入理解 Node.js 进程与线程
原文链接: https://mp.weixin.qq.com/s?__biz=MzAxODE2MjM1MA==&mid=2651557398&idx=1&sn=1fb991da ...
- 避免uncaughtException错误引起node.js进程崩溃
uncaughtException 未捕获的异常, 当node.js 遇到这个错误,整个进程直接崩溃. 或许这俩个人上辈子一定是一对冤家. 或许这俩个人经历了前世500次的回眸才换来了今生的相遇,只可 ...
- Node.js 进程
process 是全局对象,能够在任意位置访问,是 EventEmitter 的实例. 退出状态码 当没有新的异步的操作等待处理时,Node 正常情况下退出时会返回状态码 0 .下面的状态码表示其他状 ...
- [Node.js与数据库]node-mysql 模块介绍
[Node.js与数据库]node-mysql 模块介绍 转载至:https://itbilu.com/nodejs/npm/NyPG8LhlW.html#multiple-statement-q ...
随机推荐
- DotNetty 使用ByteToMessageDecoder 国家部标808协议封装
DotNetty 开源地址 https://github.com/Azure/DotNetty 个人博客地址 http://www.dncblogs.cn/Blog/ShowBlog/70 1.国 ...
- T-SQL判断是否存在表、临时表
利用SQL SERVER的系统函数 object_id() 可以判断是否存在表.临时表, object_id() 的作用是返回架构范围内对象的数据库对象标识.(即返回系统视图 sys.objects ...
- Spring Boot项目搭建
1.Spring Boot概述 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人 ...
- Java反编译工具Luyten介绍
比较精准的一个java反编译工具,笔者有时候用jd-gui反编译不出来的class用luyten都可以反编译出来. 官方网站:https://github.com/deathmarine/Luyten ...
- 《Python绝技:运用Python成为顶级黑客》 用Python进行渗透测试
1.编写一个端口扫描器 TCP全连接扫描.抓取应用的Banner #!/usr/bin/python #coding=utf-8 import optparse import socket from ...
- python爬虫3——获取审查元素(板野友美吧图片下载)
测试环境:python2.7 + beautifulsoup4.4.1 + selenium2.48.0 测试网址:http://tieba.baidu.com/p/2827883128 目的是下载该 ...
- [As3.0] 获取本机信息
package { import flash.display.Sprite; import flash.events.Event; import flash.net.NetworkInfo; impo ...
- ApplicationLoader登录失败. Please sign in with an app-specific password.
打包时登录ApplicationLoader时 报错:Please sign in with an app-specific password. You can create one at apple ...
- MySQL介绍及安装(一)
一.关系型数据库和非关系型数据库 1.1:关系型数据库 关系型数据库是把复杂的数据结构归结为简单的二元关系(即二维表格的形式),在关系型数据库中,对数据的操作几乎全部建立在一个或多个关系表格上的,通过 ...
- ajax实现快递单号查询
效果:(代码写的有点乱,自行修改就可以了) 源码: index.php <!DOCTYPE html> <html lang="en"> <head& ...