ZSH에서 방금 시작된 프로세스의 PID 표시

ZSH에서 방금 시작된 프로세스의 PID 표시

방금 시작한 프로세스의 PID를 명령 줄 끝에 표시할 수 있습니까?

Example:
root in ~: mysqld .................. [PID 34567]
12121 mysql-logs start to come in...
12125 more logs...

예를 들어, 두 개의 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

프로세스를 ^+C, ^+D 또는 ^+Z할 수 없으며 이것이 어떤 프로세스인지 알아내는 유일한 방법은 (이미 언급했듯이) top을 통해서입니다. 프로세스를 백그라운드에 둘 수도 없기 때문에 PID를 직접 얻을 수 있는 방법이 없습니다. mysqld && 에코 $! $를 보여줍니다! 0입니다.

프로세스가 시작되자마자 PID가 표시되고 실제 출력이 시작되기를 원합니다.

답변1

귀하의 마지막 의견을 읽은 후 귀하가 터미널에서 보고 있는 프로세스의 PID를 알고 싶어한다는 것을 이해합니다. 우리 모두는 이와 같은 필요를 가지고 있습니다.
제가 보통 하는 일은 다음과 같습니다.

두 개의 터미널을 엽니다.

첫 번째에서는 다음의 출력을 읽습니다 mysqld.

touch   mysql.log
tail -f mysql.log

두 번째에서는 mysqld백그라운드에서 실행됩니다.

mysqld >mysql.log 2>&1 &
ps f

나는 이 두 번째 터미널을 사용하여 control/spy 를 사용합니다 mysqld.

이것이 도움이 되기를 바랍니다.
건배.

답변2

다음을 사용하여 백그라운드에서 프로세스를 시작할 수 있습니다.

mysqld &

일반적으로 [pid]가 표시됩니다. 에코하지 않으면 다음을 수행합니다.

mysqld & echo pid=$!

포그라운드에서 데몬을 실행하려면 포그라운드로 다시 가져오면 됩니다.

mysqld & echo pid=$! ; fg

관련 정보