关于ps选项的r命令
与man ps一致,它表明
r Restrict the selection to only running processes.
与ps --help a一致,它表明
r only running processes
如果在tty6中执行sleep 5000 &命令,然后执行jobs
[1]+ Running sleep 5000 &
它是预期的,并观察运行的术语出现。它既是文件的来源。
现在,如果在相同的tty中执行ps r命令,则显示:
PID TTY STAT TIME COMMAND
我正在启动一个长时间运行的过程(在Java中,在不相关的情况下),然后通过ps捕获它的PID。我基本上是这么做的:
Process longRunningProcess = new ProcessBuilder(...).start();
Process psProcess = new ProcessBuilder("ps").start();
psProcess.waitFor();
// extract the PID from the output of psProcess
或在Bash中有效地等效:
$ long_running_process > /dev/n
根据fs/proc/array.c:130,以下数组定义了各种进程状态:
/*
* The task state array is a strange "bitmap" of
* reasons to sleep. Thus "running" is zero, and
* you can test for combinations of others with
* simple bit tests.
*/
static const char * const task_state_array[] = {
/* states in TASK_R
以下是我编写的程序,用于在linux中启动进程并在控制台中打印结果。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Driver {
public static void main(String[] args) {
try {
Process process = new ProcessBuilder("/usr/bin