Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Java Program to Shut Down Computer in Linux

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this program, we will shut down the Computer if the operating System is Linux. So, Firstly we will check that the System on which we are running Java Program is Linux or not. If the operating system is not Linux then we would not proceed further and print “Unsupported Operating System”. If it is a Linux operating system then the user will enter the time (in seconds) so that after that time PC would shut down.

Here time (in seconds) doesn’t include the time taken by Your System to shut down. For Example: if the user will input 1 sec then it consists of 1 second plus your system time required to shut down. This is because due to system architecture, availability of RAM, etc. affects the Shutting Down Speed.


  1. Import Required Packages.
  2. Check your PC has Linux Operating System or Not.
  3. If it is not Linux then print “Unsupported Operating System”.
  4. IF it is Linux the take input about “After how many seconds the PC will shut Down” to the user.
  5. PC will shut down.

Below is the implementation of the above approach:


// Java Program to Shut Down Computer
// when Operating System is Linux.
import java.util.Scanner;
public class SystemShutDown {
    public static void main(String args[])
        throws IOException
        // Initialized to  take input from user in seconds
        int seconds;
        // Find Out Operating System
        String operatingSystem
            = System.getProperty("");
        // Print Operating System of Computer
        System.out.println("Name of Operating System:"
                           + operatingSystem);
        // Check if Computer Operating System is Linux or
        // not
        if (operatingSystem.equals("Linux")) {
            // Returns the runtime object associated with
            // the current Java application.
            Runtime runTime = Runtime.getRuntime();
            // Take input from user in seconds
            seconds = 5;
            // Retrieve current Runtime Environment
            Process processing
                = runTime.exec("shutdown -h -t " + seconds);
            // Shutting Down the System


Name of Operating System:Linux  
//Shutting Down your Linux system

My Personal Notes arrow_drop_up
Last Updated : 08 Oct, 2021
Like Article
Save Article
Similar Reads
Related Tutorials