PowerShell get the current process PID tips _powershell

Source: Internet
Author: User

This article describes how to get the PID of the current PowerShell process in PowerShell and then use it to do something interesting.

Have you ever tried to enter "$pid" in the PowerShell command line window? Try.

Copy Code code as follows:

PS c:\users\zhanghong> $pid

For PID, we seem to be not unfamiliar. Yes, it is the process ID of a process. Whose process ID is the "$pid" here? Is the process ID of the PowerShell process for the current PowerShell this command line window. Note that the small series to open a Cmd.exe, and then in the cmd window input powershell into the PowerShell environment. So, here's the PID, not the Cmd.exe process ID, but the Powershell.exe process ID.

Well, after figuring out what this "$pid" is, let's take a look at what it does. Obviously, we can get to the current PowerShell process object through this "$pid". Then look at what time it started and kill the process.

First show the current time, and then see how long the process started.

PS c:\users\zhanghong> Get-date
September 18, 2013 9:05:07

PS c:\users\zhanghong> (Get-process-pid $pid). starttime
September 18, 2013 9:03:34

Kill it, and notice the change in the command prompt. has been returned to the Cmd.exe environment by the PowerShell environment. The kill here is Stop-process this cmdlet.

Copy Code code as follows:

PS c:\users\zhanghong> Kill $pid


Okay, about PowerShell. Get the current command line window process PID, small series on the introduction of so many, I hope to help you, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.