显示刚刚在 ZSH 中启动的进程的 PID

mml*_*lac 5 zsh shell process pid

我可以显示我刚刚启动的进程的 PID,理想情况下在命令行的末尾吗?

Example:
root in ~: mysqld .................. [PID 34567]
12121 mysql-logs start to come in...
12125 more logs...
Run Code Online (Sandbox Code Playgroud)

例如,当我启动两个mysqld进程而第二个进程不“工作”(端口等)时,我无法确定哪个守护进程具有哪个 PID。

具体例子:

mysqld >/dev/null                                                                                                                                     130 ?
120126 15:44:05 [Note] Plugin 'FEDERATED' is disabled.
120126 15:44:05 InnoDB: The InnoDB memory heap is disabled
120126 15:44:05 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120126 15:44:05 InnoDB: Compressed tables use zlib 1.2.3
120126 15:44:05 InnoDB: Initializing buffer pool, size = 128.0M
120126 15:44:05 InnoDB: Completed initialization of buffer pool
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
120126 15:44:05  InnoDB: Retrying to lock the first data file
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Unable to lock ./ibdata1, error: 35
Run Code Online (Sandbox Code Playgroud)

我既不能 ^+C、^+D 也不能 ^+Z 过程,找出这是什么过程的唯一方法是通过 top (如前所述)。由于我什至无法将进程置于后台,因此我无法直接获取 PID。mysqld && 回声 $! 显示 $! 是 0。

我希望在进程启动后立即显示 PID,然后实际输出开始。

oHo*_*oHo 1

读完你的最后一条评论后,我知道你想知道你在终端中查看的进程的 PID。我们有同样的需求。
这就是我通常做的事情:

我打开两个终端。

在第一个中,我将阅读以下输出mysqld

touch   mysql.log
tail -f mysql.log
Run Code Online (Sandbox Code Playgroud)

在第二个中,我mysqld在后台运行:

mysqld >mysql.log 2>&1 &
ps f
Run Code Online (Sandbox Code Playgroud)

我使用第二个终端来控制/监视mysqld

希望这会有所帮助。
干杯。