JAVA detects whether the specified process is running __java

Source: Internet
Author: User

Import Java.io.BufferedReader; Import Java.io.InputStreamReader; /** * Java detects whether the specified process is running. * @author java Century Network (java2000.net, laozizhu.com)/public class Testfindprocessofexe {public static void main (string[] Ar GS) {System.out.println (findprocess ("Eclipse.exe"));}/** * Detection program. * * @param the name of the processname thread, please use the exact name * @return Find return True, failed to find return false */public static Boolean findprocess (String Processnam e) {BufferedReader bufferedreader = null; try {Process proc = runtime.getruntime (). EXEC ("TASKLIST/FI/imagename eq" + ProcessName + "/" "); BufferedReader = new BufferedReader (New InputStreamReader (Proc.getinputstream ())); String line = null; while (line = Bufferedreader.readline ())!= null) {if (Line.contains (processname)) {return true;} return false; catch (Exception ex) {ex.printstacktrace (); return false;} finally {if (BufferedReader!= null) {try {Bufferedreade R.close (); \ catch (Exception ex) {}}}}

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.