0% found this document useful (0 votes)
4 views10 pages

Pratical 311

The document provides a comprehensive guide on how to download, install, and set up VirtualBox on various operating systems, including Windows, macOS, and Linux. It also covers the process of creating a bootable USB drive for installing Linux, basic Linux commands, and examples of process and thread creation in Java. Additionally, it includes instructions for managing processes and threads in Java, highlighting the use of ProcessBuilder and ExecutorService.

Uploaded by

28jeleel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Pratical 311

The document provides a comprehensive guide on how to download, install, and set up VirtualBox on various operating systems, including Windows, macOS, and Linux. It also covers the process of creating a bootable USB drive for installing Linux, basic Linux commands, and examples of process and thread creation in Java. Additionally, it includes instructions for managing processes and threads in Java, highlighting the use of ProcessBuilder and ExecutorService.

Uploaded by

28jeleel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

HOW TO RUN VIRTUAL BOX ON SYSTEM

Step 1: Download VirtualBox

1. Go to the https://www.virtualbox.org/
2. Click on "Downloads" and select the appropriate version for your operating system:
o Windows
o macOS
o Linux
o Solaris

Step 2: Install VirtualBox

For Windows

1. Double-click the downloaded .exe file.


2. Click Next on the setup wizard.
3. Choose the installation location (or leave it as default).
4. Select additional options (like creating shortcuts).
5. Click Next, then Install.
6. Click Yes if prompted by User Account Control (UAC).
7. Wait for the installation to complete and click Finish.

For macOS

1. Open the downloaded .dmg file.


2. Double-click on VirtualBox.pkg to start the installation.
3. Follow the on-screen instructions and click Continue > Install.
4. Enter your Mac administrator password if required.
5. If you see a security warning, go to System Preferences > Security & Privacy and allow
VirtualBox to run.
6. Click Finish when done.
For Linux (Ubuntu/Debian-based distros)

1. Open the terminal (Ctrl + Alt + T).


2. Run the following commands:

sudo apt update


sudo apt install virtualbox

3. Wait for the installation to complete.

Step 3: Install VirtualBox Extension Pack (Optional but Recommended)

1. Download the Extension Pack from the official VirtualBox website.


2. Open VirtualBox, go to File > Preferences > Extensions.
3. Click Add (Plus Icon) and select the downloaded extension pack.
4. Follow the prompts to install.

Step 4: Verify Installation

1. Open VirtualBox from the Start Menu (Windows) or Applications Folder (macOS/Linux).
2. If it opens without errors, the installation was successful!
LINUX SETUP

Step 1: Choose a Linux Distribution

Popular options:

• Ubuntu (beginner-friendly)
• Fedora (cutting-edge, good for developers)
• Debian (stable, but requires manual setup)
• Arch Linux (for advanced users who want customization)

Step 2: Create a Bootable USB Drive

1. Download the ISO file of your chosen Linux distro from its official website.
2. Use a tool like Rufus (Windows) or Etcher (Mac/Linux) to create a bootable USB.
3. Plug in the USB and select the correct ISO file.
4. Set the partition scheme to GPT (for UEFI) or MBR (for Legacy BIOS).
5. Click Start to make the bootable drive.

Step 3: Boot from USB

1. Restart your PC and enter the BIOS/UEFI (press F2, F12, Del, or Esc during boot).
2. Set the USB drive as the first boot option.
3. Save changes and reboot.

Step 4: Install Linux

1. Once booted, you’ll see an option like "Try" or "Install" Linux. Choose Install.
2. Follow the on-screen setup:
o Choose Language & Keyboard Layout
o Select Installation Type:
▪ Erase disk (deletes everything and installs Linux)
▪ Dual Boot (install alongside Windows)
▪ Manual Partitioning (for custom setups)
o Create a user account
o Set up partitions (if required)
3. Click Install and wait for it to complete.
Step 5: Reboot & Finalize Setup

• Remove the USB when prompted.


• Log in and update the system using:

sudo apt update && sudo apt upgrade -y # Ubuntu/Debian


sudo dnf update -y # Fedora
sudo pacman -Syu # Arch
Linux Command

1. Basic Commands

• ls → List files and directories

ls -l # Long format listing


ls -a # Show hidden files

• pwd → Print current working directory

pwd

• cd → Change directory

cd /home/user/Documents
cd .. # Move up one directory

• mkdir → Create a new directory

mkdir new_folder

• rm → Remove files or directories

rm file.txt
rm -r folder_name # Remove directory

2. File Management

• touch → Create a new empty file

touch newfile.txt

• cp → Copy files and directories

cp file.txt /destination/
cp -r folder/ /destination/

• mv → Move or rename files

mv oldname.txt newname.txt
mv file.txt /new/location/

• cat → View file contents


cat file.txt

• less → View file contents page by page

less file.txt

3. User Management

• whoami → Display current user

whoami

• who → Show logged-in users

who

• sudo → Run a command as administrator

sudo apt update

• passwd → Change user password

passwd
PROCESS CREATION USING JAVA / C++

In Java (Using ProcessBuilder)

Java provides ProcessBuilder and Runtime.exec() for creating processes.

import java.io.*;

public class ProcessExample {


public static void main(String[] args) {
try {
ProcessBuilder processBuilder = new ProcessBuilder("notepad.exe");
Process process = processBuilder.start();

process.waitFor();

System.out.println("Process finished!");
} catch (Exception e) {
e.printStackTrace();
}
}
}

This will open Notepad (on Windows). Replace "notepad.exe" with another command if needed.
Process Termination

Java allows you to destroy a process using Process.destroy() or Process.destroyForcibly().

Example: Start & Kill Notepad (Windows)

import java.io.*;

public class ProcessTerminationExample {


public static void main(String[] args) {
try {
// Start a process (Notepad in Windows)
ProcessBuilder processBuilder = new ProcessBuilder("notepad.exe");
Process process = processBuilder.start();

// Wait a few seconds before killing it


Thread.sleep(5000);

// Terminate the process


process.destroy(); // Graceful termination
// process.destroyForcibly(); // Force termination if needed

System.out.println("Process terminated!");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Explanation:

• destroy(): Tries to terminate the process gracefully.


• destroyForcibly(): Force kills the process.
Thread Creation

Example 1: Using Thread Class (Postfix Approach)

class MyThread extends Thread {


public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println("Thread 1: " + i);
try {
Thread.sleep(500); // Simulating some work
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

public class ThreadExample {


public static void main(String[] args) {
MyThread t1 = new MyThread();
t1.start(); // Start the thread

for (char c = 'A'; c <= 'E'; c++) {


System.out.println("Main Thread: " + c);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

Explanation:

• MyThread extends Thread and overrides run().


• The start() method begins execution in a separate thread.
• The main thread prints letters while MyThread prints numbers.
Example 2: Using ExecutorService (Thread Pool)

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class Worker implements Runnable {


private int id;

public Worker(int id) {


this.id = id;
}

@Override
public void run() {
System.out.println("Thread " + id + " is running");
try {
Thread.sleep(1000); // Simulating some work
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Thread " + id + " has finished");
}
}

public class ThreadPoolExample {


public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(3);

for (int i = 1; i <= 5; i++) {


executor.execute(new Worker(i));
}

executor.shutdown(); // Shuts down the executor after task completion


}
}

Explanation:

• ExecutorService creates a thread pool with Executors.newFixedThreadPool(3).


• execute(new Worker(i)) assigns tasks to the pool.
• shutdown() ensures all tasks finish before program exits.

You might also like