Sopalajo de Arrierez
Sopalajo de Arrierez

Reputation: 3860

Cygwin: How can I obtain the PID of a program started by CygStart?

If I open a CygWin Bash shell and do:

Luis@Kenobi ~/Temporal
$ notepad &
[1] 1880

Luis@Kenobi ~/Temporal
$ echo $!
1880

the PID variable $! is correct.
But if I do:

Luis@Kenobi ~/Temporal
$ cygstart notepad

Luis@Kenobi ~/Temporal
$ echo $!
[No results]

This time $!has no value at all.

How can I get the PID of the just started CygStart program?

Upvotes: 3

Views: 1426

Answers (1)

Adrian Frühwirth
Adrian Frühwirth

Reputation: 45576

You cannot. You can get the PID of the cygstart process via

$ cygstart notepad &
$ echo "$!"

but this won't do you any good since I guess you want to have control over the notepad process. Since cygstart starts notepad via Windows' ShellExecuteW and because it consequently won't be a child process of cygstart/your current shell there is no way for you to kill it by killing cygstart.

You can easily verify this with Process Explorer.

Upvotes: 2

Related Questions