ps

How to control a script is not already running?

有些话、适合烂在心里 提交于 2019-12-12 01:59:13
问题 I have a shell script executed by cron and I want to control that it's not already running. This is my control test: set -A processes ps -elf | grep -v grep | grep -E "/bin/ksh.+scriptName" | while read line ;do processes[${#processes[@]}]="$line";done if [ ${#processes[@]} -gt 1 ]; then for i in {0..$((${#processes[@]}-1))}; do echo "${processes[$i]}"; done exit 1 fi The problem is that this control returns sometimes 2 processes (of itself): F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY

Using awk to get a specific string in line

为君一笑 提交于 2019-12-12 01:57:58
问题 I have a java process containing multiple strings in the ps output. I just want a particular string out of it. For example, I have root 5565 7687 0 Nov20 ? 00:00:54 /bin/java -Xms256m -Xmx512m -XX:MaxPermSize=128m -XX:PermSize=256m -XX:MaxPermSize=256m -Dstdout.file=/tmp/std.out -da -Dext.dir.class=profiles/ -Dprocess.name=java1 -Djava.security.policy=security.policy I want just want process.name=java1 and require nothing else from the ps output. I was unable to find a tangible way to do so

how to check if ruby script is running in background from PHP script?

限于喜欢 提交于 2019-12-11 16:47:50
问题 say a ruby script is running ruby.rb SOMEUSERID using PHP, how can i find out whether something exactly like that is currently running or not ? Currently i am using PID to check but im not sure if this is efficient. What if there are lot of users running the ruby script, and the ruby script unexpectedly closes. The php script now looks for this PID, and then it turns out it's somebody else's ruby script....trouble ensues. 回答1: I don't like the idea but you can do this on linux exec('ps -A |

restart a php script using shell script

Deadly 提交于 2019-12-11 12:18:38
问题 i am using shell script to monitor the working of a php script. My aim is that this php script should not sleep / terminated and must always be running.The code i used is - ps aux | grep -v grep | grep -q $file || ( nohup php -f $file -print > /var/log/file.log & ) now this idea would not work for cases if the php script got terminated(process status code T). Any idea to handle that case. can such processes be killed permanently and then restarted. 回答1: If the script is exiting after it's

linux常用命令-ps

家住魔仙堡 提交于 2019-12-10 17:27:53
PS 命令是什么 查看它的man手册可以看到,ps命令能够给出当前系统中进程的快照。它能捕获系统在某一事件的进程状态。如果你想不断更新查看的这个状态,可以使用top命令。 ps命令支持三种使用的语法格式 UNIX 风格,选项可以组合在一起,并且选项前必须有“-”连字符 BSD 风格,选项可以组合在一起,但是选项前不能有“-”连字符 GNU 风格的长选项,选项前有两个“-”连字符 我们能够混用这几种风格,但是可能会发生冲突。本文使用 UNIX 风格的ps命令。这里有在日常生活中使用较多的ps命令的例子。 1. 不加参数执行ps命令 这是一个基本的 ps 使用。在控制台中执行这个命令并查看结果。 结果默认会显示4列信息。 PID: 运行着的命令(CMD)的进程编号 TTY: 命令所运行的位置(终端) TIME: 运行着的该命令所占用的CPU处理时间 CMD: 该进程所运行的命令 这些信息在显示时未排序。 2. 显示所有当前进程 使用 -a 参数。-a 代表 all。同时加上x参数会显示没有控制终端的进程。 $ ps -ax 这个命令的结果或许会很长。为了便于查看,可以结合less命令和管道来使用。 $ ps -ax | less 3. 根据用户过滤进程 在需要查看特定用户进程的情况下,我们可以使用 -u 参数。比如我们要查看用户‘kseven‘的进程,可以通过下面的命令: $ ps

线上Web应用故障排查之高CPU占用

匆匆过客 提交于 2019-12-10 16:38:20
故障描述 Web服务启动之后,服务器CPU使用率瞬间飙升到90%。此时接口服务频繁超时。 故障处理 由于短时间无法定位和修复问题,以免影响终端用户操作体验,采取了回滚操作。 故障问题分析 一般一个应用CPU使用率很高,通常都是由于程序中的死循环引起的。 故障问题定位过程 ####1、使用 top 命令查看占用 CPU 较高的进程 可以看到 PID 为 26484 这个进程的 CPU 占用率最高。 ####2、定位具体进程 使用 'ps aux | grep 26484' 或 'ps -ef | grep 26484' 命令,定位到具体的进程 ####3、查看进程下的线程 CPU 占用情况 使用 'ps -mp 26484 -o THREAD,tid,time | sort -rn' 命令打印出该进程下的线程占用 CPU 情况 可以看到 TID 为 26762 的这个线程占用 CPU 最高 ####4、线程 ID 转换为 16 进制格式 使用 'printf "%x\n" 26762' 命令将线程 ID 转换为 16 进制格式, 以方便下一步查询线程堆栈信息 ####5、查看线程堆栈信息 使用 'jstack 26484 |grep 688a -A 30' 命令打印出高 CPU 占用的线程 26762 的堆栈信息, 如下: 从上面的输出结果就可以定位到具体出问题的代码,

How to use the S-output-modifier with Unix/Linux command ps?

流过昼夜 提交于 2019-12-10 11:41:01
问题 The command ps -o time -p 21361 works; however what I need is the running time of the process including all the children . For example, if 21361 is a bash script, which calls other scripts, then I want the total running time, including the running time of all children. Now the ps documentation lists the "OUTPUT MODIFIER": S Sum up some information, such as CPU usage, from dead child processes into their parent. This is useful for examining a system where a parent process repeatedly forks off

popen creates an extra sh process

我的梦境 提交于 2019-12-10 10:45:40
问题 I am trying to execute (fork off) a command with popen and what I see is, there is an extra sh -c "my_command process" is also there. I want to minimize number of processes so is it possible to get rid of it? ps output: root@home% ps awux | grep my_command root 638 0.0 0.1 040 1424 ?? I 10:12PM 0:00.00 sh -c my_command /home/war root 639 0.0 0.0 608 932 ?? S 10:12PM 0:00.01 my_command /home/war After reading manpage, I know this is how popen() works. Answer to problem above was provided by @R

Is there any way to get ps output programmatically?

孤者浪人 提交于 2019-12-10 08:46:32
问题 I've got a webserver that I'm presently benchmarking for CPU usage. What I'm doing is essentially running one process to slam the server with requests, then running the following bash script to determine the CPU usage: #! /bin/bash for (( ;; )) do echo "`python -c 'import time; print time.time()'`, `ps -p $1 -o '%cpu' | grep -vi '%CPU'`" sleep 5 done It would be nice to be able to do this in Python so I can run it in one script instead of having to run two. I can't seem to find any platform

JDBC连接数据库插入null值

♀尐吖头ヾ 提交于 2019-12-10 05:48:38
使用jdbc插入null值 String sql = "insert into person (name,age) values(?,?)"; PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1,p.getName); ps.setInt(2,p.getAge); 此时,如果p的age为null,设值的时候会报错。 使用如下写法插入null值 if(p.getName !=null){ ps.setInt(2,p.getName ); }else{ ps.setNull(2, Types.NULL); } 来源: CSDN 作者: 小白小新 链接: https://blog.csdn.net/qq_40264864/article/details/103457312