Java Program to Shut Down Computer in Linux Last Updated : 08 Oct, 2021 Comments Improve Suggest changes Like Article Like Report 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. Approach: Import Required Packages.Check your PC has Linux Operating System or Not.If it is not Linux then print “Unsupported Operating System”.IF it is Linux the take input about “After how many seconds the PC will shut Down” to the user.PC will shut down.Below is the implementation of the above approach: Java // Java Program to Shut Down Computer // when Operating System is Linux. import java.io.IOException; 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("os.name"); // 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 System.exit(0); } Output: Name of Operating System:Linux //Shutting Down your Linux system Comment More infoAdvertise with us Next Article How to Block or Disable Normal User Logins in Linux? J jagroopofficial Follow Improve Article Tags : Linux-Unix Technical Scripter 2020 Similar Reads How to Kill a Process in Linux | Kill Command kill command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually. kill command sends a signal to a process that terminates the process. If the user doesn't specify any signal that is to be sent along with the kill command, then a default TERM signal i 6 min read How to Block or Disable Normal User Logins in Linux? Here we will see how to block or disable normal user logins in Linux. This is a good idea to prevent Normal users from connecting to your system. We will see how to block Normal user logins using /etc/nologin file. We are going to tell the users that what is actually happening by showing them a mess 2 min read Reboot Linux System Command with Examples Rebooting a Linux system is a fundamental administrative task necessary for applying updates, troubleshooting, or system maintenance. Various commands are available to reboot a Linux system, each with specific options and use cases. This guide explores essential reboot commands such as `reboot`, `sh 11 min read Reboot Linux System Command with Examples Rebooting a Linux system is a fundamental administrative task necessary for applying updates, troubleshooting, or system maintenance. Various commands are available to reboot a Linux system, each with specific options and use cases. This guide explores essential reboot commands such as `reboot`, `sh 11 min read Batch Script - Process in Linux A Batch Script is basically a script having commands which execute sequentially. It helps users to perform repetitive tasks without human or user intervention or input. To automate some tasks like loading processes, and killing processes. Now in this article, we will write a batch script to view all 2 min read How to switch between the CLI and GUI on a Linux server The command line interface (CLI) is the text-based way to interact with Linux using keyboard commands. The graphical user interface (GUI) provides a visual desktop with icons and graphics to manage the system. Linux allows smooth transitioning between CLI and GUI. You can access the keyboard-driven 5 min read Like