pid

Identify the files opened a particular process on linux

微笑、不失礼 提交于 2019-12-03 06:02:41
问题 I need a script to identify the files opened a particular process on linux To identify fd : >cd /proc/<PID>/fd; ls |wc –l I expect to see a list of numbers which is the list of files descriptors' number using in the process. Please show me how to see all the files using in that process. Thanks. 回答1: The command you probably want to use is lsof . This is a better idea than digging in /proc , since the command is a more clear and a more stable way to get system information. lsof -p pid However,

Capturing exit status code of child process

本秂侑毒 提交于 2019-12-03 05:49:05
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() failed!\n"); exit(EXIT_FAILURE); } else { /* Close parent read and write pipes (not shown)... */ return

windows 7系统下查看被占用的端口并解除占用

≡放荡痞女 提交于 2019-12-03 04:11:00
运行输入cmd,在命令行输入 netstat -ano 查找所占用端口所在的行,如图本例子被占用端口为9999,记住对应的pid 然后输入 tasklist|findstr pid(此处为9528) ,就能看到占用该端口的进程名。 另一种方法就是打开任务管理器选择进程 因为没有pid,所以点击查看按钮,再选择列,将PID勾选 这样就能看到占用该端口的进程了,这时候可以直接点击结束进程按钮 如果是在dos窗口,则可以输入如下命令,通过pid来删除进程: taskkill /f /t /pid [PID] 也可以按照进程名删除进程,输入如下命令: taskkill /f /t /im [进程名] 最后搞定 来源: https://www.cnblogs.com/qingmuchuanqi48/p/11776417.html

Get the PID of a process started with nohup via ssh

自古美人都是妖i 提交于 2019-12-03 03:12:46
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 sleep". But I'm having trouble doing it remotely via ssh. I tried something like ssh remote_machine

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

自古美人都是妖i 提交于 2019-12-03 02:58:14
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 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) you should know the process id(pid) of the process you want to monitor Notes: HOST-RESOURCES-MIB:

How to get process status using pid?

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If I known a process's pid, how can I tell if the process is an zombie using Python ? 回答1: You could use a the status feature from psutils : import psutil p = psutil.Process(the_pid_you_want) if p.status == psutil.STATUS_ZOMBIE: .... 回答2: here's a quick hack using procfs (assuming you're using Linux): def procStatus(pid): for line in open("/proc/%d/status" % pid).readlines(): if line.startswith("State:"): return line.split(":",1)[1].strip().split(' ')[0] return None this function should return 'Z' for zombies. 文章来源: How to get process status

Change default route in docker container

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a docker container that is connected to two networks, the default bridge and a custom bridge. Via the default, it is linked to another container only in the default network and via the custom bridge, it gets an IP address in local network. LAN -- [homenet] -- container1 -- [bridge] -- container2 sudo docker network inspect homenet [{ "Name": "homenet", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": {}, "Config": [{ "Subnet": "192.168.130.0/24", "Gateway": "192.168.130.8",

Avoiding a fork()/SIGCHLD race condition

匿名 (未验证) 提交于 2019-12-03 02:15:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;) { if ( is_time_to_make_babies ) { pid = fork(); if (pid == -1) { /* fail */ } else if (pid == 0) { /* child stuff */ print "child started" exit } else { /* parent stuff */ print "parent forked new child ", pid children.add(pid); } } } // SIGCHLD handler sigchld_handler(signo) { while ( (pid = wait(status, WNOHANG)) > 0 ) { print "parent caught SIGCHLD from ", pid children.remove(pid); } } In the above example there's a race-condition. It's possible

快速将数据变为树结构

不羁岁月 提交于 2019-12-03 01:49:45
data = [ {id:1, pid:0}, {id:2, pid:1}, {id:3, pid:1}, {id:4, pid:3}, {id:5, pid:2}, {id:6, pid:0}, ] parents = {} data.forEach((v,k)=>{ console.log(k, v) if (!parents[v["pid"]]) { parents[v["pid"]] = [] } parents[v["pid"]].push(v) }) console.log(parents) function getChilds(id) { if (!parents[id]) { return [] } var childs = parents[id]; return childs; } 来源: https://www.cnblogs.com/lst619247/p/11770094.html

Get the pid of a running playbook for use within the playbook

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: When we run a playbook, with verbose output enabled, in the ansible logs we can see something like this: 2016-02-03 12:51:58,235 p=4105 u=root | PLAY RECAP I guess that the p=4105 is the pid of the playbook when it ran. Is there a way to get this pid inside the playbook during its runtime (as a variable for example)? 回答1: This sounds a little like an XY problem , but one option may be to spawn a shell with the shell command and then ask for the parent PID: - name : get pid of playbook shell : | echo "$PPID" register : playbook_pid