How we can get pid of own application?

How we can get pid of own application?

Below code will give you some important information, which can be helpful for you.

    public static void main(String[] args)
    {
        System.out.println(ManagementFactory.getRuntimeMXBean().getName());
        System.out.println(ManagementFactory.getRuntimeMXBean().getBootClassPath());
        System.out.println(ManagementFactory.getRuntimeMXBean().getClassPath());
        System.out.println(ManagementFactory.getRuntimeMXBean().getLibraryPath());
        System.out.println(ManagementFactory.getRuntimeMXBean().getManagementSpecVersion());
        System.out.println(ManagementFactory.getRuntimeMXBean().getSpecName());
        System.out.println(ManagementFactory.getRuntimeMXBean().getSpecVendor());
    }

But

System.out.println(ManagementFactory.getRuntimeMXBean().getName());

It will give you own application pid.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s