GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Technologies
  • Databases
  • Computer Programming
  • Web Development
  • Java Technologies
  • Computer Science
  • Mobile Development
  • Big Data & Analytics
  • Microsoft Technologies
  • DevOps
  • Latest Technologies
  • Machine Learning
  • Digital Marketing
  • Software Quality

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialspoint.com — Java Process Class

java package tutorial
  • Java.lang - Home
  • Java.lang - Boolean
  • Java.lang - Byte
  • Java.lang - Character
  • Java.lang - Character.Subset
  • Java.lang - Character.UnicodeBlock
  • Java.lang - Class
  • Java.lang - ClassLoader
  • Java.lang - Compiler
  • Java.lang - Double
  • Java.lang - Enum
  • Java.lang - Float
  • Java.lang - InheritableThreadLocal
  • Java.lang - Integer
  • Java.lang - Long
  • Java.lang - Math
  • Java.lang - Number
  • Java.lang - Object
  • Java.lang - Package
  • Java.lang - Process
  • Java.lang - ProcessBuilder
  • Java.lang - Runtime
  • Java.lang - RuntimePermission
  • Java.lang - SecurityManager
  • Java.lang - Short
  • Java.lang - StackTraceElement
  • Java.lang - StrictMath
  • Java.lang - String
  • Java.lang - StringBuffer
  • Java.lang - StringBuilder
  • Java.lang - System
  • Java.lang - Thread
  • Java.lang - ThreadGroup
  • Java.lang - ThreadLocal
  • Java.lang - Throwable
  • Java.lang - Void
  • Java.lang - Interfaces
  • Java.lang - Errors
  • Java.lang - Exceptions
  • Java.lang Package Useful Resources
  • Java.lang - Useful Resources
  • Java.lang - Discussion
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who

Java Process Class



Previous
Quiz
Next

Introduction

The Java Process class provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.

Class Declaration

Following is the declaration for java.lang.Process class −

public abstract class Process
   extends Object

Class constructors

Sr.No. Constructor & Description
1

Process()

This is the Single Constructor.

Class methods

Sr.No. Method & Description
1 abstract void destroy()

This method kills the subprocess.

2 abstract int exitValue()

This method returns the exit value for the subprocess.

3 abstract InputStream getErrorStream()

This method gets the error stream of the subprocess.

4 abstract InputStream getInputStream()

This method gets the input stream of the subprocess.

5 abstract OutputStream getOutputStream()

This method gets the output stream of the subprocess.

6 abstract int waitFor()

This method causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.

Methods inherited

This class inherits methods from the following classes −

  • java.lang.Object

Destroying a Process Example

The following example shows the usage of Process destroy() method. We've created a Process object for notepad executable. Then we've kept system to wait for 10 seconds and then using destroy() method, notepad process is killed and a message is printed.

package com.tutorialspoint;

public class ProcessDemo {

   public static void main(String[] args) {
      try {
         // create a new process
         System.out.println("Creating Process...");
         Process p = Runtime.getRuntime().exec("notepad.exe");

         // wait 10 seconds
         System.out.println("Waiting...");
         Thread.sleep(10000);

         // kill the process
         p.destroy();
         System.out.println("Process destroyed.");

      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

Output

Let us compile and run the above program, this will produce the following result −

Creating Process...
Waiting...
Process destroyed.
Tutorix - AI Tutor
Previous Quiz Next
Advertisements
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.