pid

JSON.stringify方法报错:Converting circular structure to JSON

∥☆過路亽.° 提交于 2019-12-03 16:53:57
别以为JSON.parse(JSON.stringify(data))做深拷贝无敌,对于以下这种情况,当你需要保留父级对象,即 对象存在循环引用,就会报错。 var a = [ { "id":5, "pid":2, "categoryName":"搜索行为", }, { "id":6, "pid":3, "categoryName":"购买力", } ] a.map(item => { item.parent = item return item }) let b = JSON.stringify(a) console.log(b)  报错   正确的方法是: var a = [ { "id":5, "pid":2, "categoryName":"搜索行为", }, { "id":6, "pid":3, "categoryName":"购买力", } ] a.map(item => { item.parent = JSON.parse(JSON.stringify(item)) // 注意这里 return item }) let b = JSON.stringify(a) console.log(b)   更精简的情况: var a = {}; a.o = a; console.log(JSON.stringify(o))    来源: https://www.cnblogs

Capturing exit status code of child process

僤鯓⒐⒋嵵緔 提交于 2019-12-03 16:32:22
问题 I have a function that forks a process, duplicates file descriptors for input and output buffers, and then runs execl on a command passed in via a string called cmd : static pid_t c2b_popen4(const char* cmd, int pin[2], int pout[2], int perr[2], int flags) { pid_t ret = fork(); if (ret < 0) { fprintf(stderr, "fork() failed!\n"); return ret; } else if (ret == 0) { /* Assign file descriptors to child pipes (not shown)... */ execl("/bin/sh", "/bin/sh", "-c", cmd, NULL); fprintf(stderr, "execl()

鸟哥私房菜基础篇:程序管理与 SELinux 初探习题

亡梦爱人 提交于 2019-12-03 13:42:56
猫宁!!! 参考: http://cn.linux.vbird.org/linux_basic/0440processcontrol.php 1- 简单说明什么是程序 (program) 而什么是程序 (process)? 程序 (program) 是系统上面可以被运行的文件,由於 Linux 的完整档名 (由 / 写起) 仅能有一个, 所以 program 的档名具有单一性。当程序被运行后,就会启动成程序 (process), 一个 program 可以被不同的使用者或者相同的使用者重复的运行成为多个程序, 且该程序所造成的程序还因为不同的使用者,而有不同的权限,且每个 process 几乎都是独立的。 2- 我今天想要查询 /etc/crontab 与 crontab 这个程序的用法与写法,请问我该如何线上查询? 查询 crontab 命令可以使用 man crontab 或 info crontab ,至於查询 /etc/crontab ,则可以使用 man 5 crontab 罗! 3- 我要如何查询 crond 这个 daemon 的 PID 与他的 PRI 值呢? ps aux | grep crond 即可查到! 4- 我要如何修改 crond 这个 PID 的优先运行序? 先以 ps aux 找到 crond 的 PID 后,再以: renice -n number

How to find the memory consumption of a particular process in linux for every 5 seconds

强颜欢笑 提交于 2019-12-03 13:38:18
问题 I just want to know how to find the memory consumption of a particular process for particular time(say 5 seconds) I am new to linux. So, detailed steps of doing that will be appreciated 回答1: you may use SNMP to get the memory and cpu usage of a process in a particular device in network :) Requirements: the device running the process should have snmp installed and running snmp should be configured to accept requests from where you will run the script below(it may be configured in snmpd.conf)

Get the PID of a process started with nohup via ssh

二次信任 提交于 2019-12-03 12:52:48
问题 I want to start a process using nohup on a remote machine via ssh. The problem is how to get the PID of the process started with nohup, so the "process actually doing something", not some outer shell instance or the like. Also, I want to store stdout and stderr in files, but that is not the issue here... Locally, it works flawlessly using nohup sleep 30 > out 2> err < /dev/null & echo $! It is echoing me the exact PID of the command "sleep 30", which I can also see using "top" or "ps aux|grep

multiprocessing.Pool with maxtasksperchild produces equal PIDs

强颜欢笑 提交于 2019-12-03 12:23:18
I need to run a function in a process, which is completely isolated from all other memory, several times. I would like to use multiprocessing for that (since I need to serialize a complex output coming from the functions). I set the start_method to 'spawn' and use a pool with maxtasksperchild=1 . I would expect to get a different process for each task, and therefore see a different PID: import multiprocessing import time import os def f(x): print("PID: %d" % os.getpid()) time.sleep(x) complex_obj = 5 #more complex axtually return complex_obj if __name__ == '__main__': multiprocessing.set_start

JDK内置工具命令

谁说胖子不能爱 提交于 2019-12-03 11:40:30
javap Java反编译工具,主要用于根据Java字节码文件反汇编为Java源代码文件 用法:javap 用法 描述 javap -help —help -? 输出此用法消息 javap -version 版本消息 javap -v -verbose 输出附加信息 javap -l 输出行号和本地变量表 javap -public 仅显示公共类和成员 javap -protected 显示受保护的/公共类和成员 javap -package 显示程序包/受保护的/公共类和成员 (默认) javap -p -private 显示所有类和成员 javap -c 对代码进行反汇编 javap -s 输出内部类型签名 javap -sysinfo 显示正在处理的类的系统信息 (路径, 大小, 日期, MD5 散列) javap -constants 显示最终常量 javap -classpath 指定查找用户类文件的位置 javap -cp 指定查找用户类文件的位置 javap -bootclasspath 覆盖引导类文件的位置 jps jps(Java Virtual Machine Process Status Tool)显示当前所有Java进程pid的命令 用法:jps [options] [hostid] 用法 描述 jps -q 仅输出VM标识符 jps -m 输出main

How to get variable from text file into Bash variable

醉酒当歌 提交于 2019-12-03 11:39:58
问题 Simple question, in BASH I'm trying to read in a .pid file to kill a process. How do I read that file into a variable. All the examples I have found are trying to read in many lines. I only want to read the one file that just contains the PID #!/bin/sh PIDFile="/var/run/app_to_kill.pid" CurPID=(<$PIDFile) kill -9 $CurPID 回答1: You're almost there: CurPID=$(<"$PIDFile") In the example you gave, you don't even need the temp variable. Just do: kill -9 $(<"$PIDFile") 回答2: POSIX portable way: $

How to list all background pids in bash

会有一股神秘感。 提交于 2019-12-03 11:07:56
Either I am not able to phrase my search correctly or the answer is not easy to find!, but I am trying to figure out how to list all of my background task PIDs. For example: So far I have found that to list the last PID we use: $! But now I want to list the PID of the task before that (if one exists), but I can't find how to do that. Utlimatly I want to list all my background task PIDs. I know we can also find last job ID with: %% (last job in list) %1 (first job in list) %2 (second job in list) But the same does not seem to work for process id? Thanks all :) Use ps S . For example: $ vim & [1

JVM性能调优监控工具jps、jstack、jmap、jhat、jstat、hprof

早过忘川 提交于 2019-12-03 10:48:27
前提概要: JDK本身提供了很多方便的JVM性能调优监控工具,除了集成式的VisualVM和jConsole外,还有jps、jstack、jmap、jhat、jstat、hprof等小巧的工具,每一种工具都有其自身的特点,用户可以根据你需要检测的应用或者程序片段的状况,适当的选择相应的工具进行检测。接下来的两个专题分别会讲VisualVM的具体应用。 现实企业级Java开发中,有时候我们会碰到下面这些问题: OutOfMemoryError,内存不足 内存泄露 线程死锁 锁争用(Lock Contention) Java进程消耗CPU过高 ...... 这些问题在日常开发中可能被很多人忽视(比如有的人遇到上面的问题只是重启服务器或者调大内存,而不会深究问题根源),但能够理解并解决这些问题是Java程序员进阶的必备要求。 一、 jps(Java Virtual Machine Process Status Tool) : 基础工具 实际中这是最常用的命令,下面要介绍的小工具更多的都是先要使用jps查看出当前有哪些Java进程,获取该Java进程的id后再对该进程进行处理。 jps主要用来输出JVM中运行的进程状态信息。语法格式如下: Java代码 jps [options] [hostid] 如果不指定hostid就默认为当前主机或服务器。 命令行参数选项说明如下: Java代码