This project aims to provide basic understanding of operating system kernel development. In this project,we build an operating system’s kernel simulation. It is divided into different phases.
Memory management
I/O management
Other operations
After this we create a Process Management menu. In this menu, we create buttons for the different operations that can be performed on a process. These operations are following:
Operations on a Process related to Process Management
Create a process
Destroy a process
Suspend a process
Resume a process
Block a process
Wakeup a process
Dispatch a process
Change process priority
Process communication with other processes
First of all, a name to your operating system and build a control panel for operating system simulation which perform the following operations.
Process management Memory management
I/O management
Other operations
After this we create a Process Management menu. In this menu, we create buttons for the different operations that can be performed on a process. These operations are following:
Create a process
Destroy a process
Suspend a process
Resume a process
Block a process
Wakeup a process
Dispatch a process
Change process priority
Process communication with other processes
Source Code
MyProcessthread.java
package riu.cms7425.ProcessManagement; public class MyProcessthread extends Thread{ String name; public MyProcessthread(String name){ this.name = name; } public void run(){ Resource r = new Resource(); for(int i = 0;i<20;i++){ System.out.println(name + "Hello world\n" + r.printer + "\n"+ r.monitor); try{ this.wait(500); } catch(Exception e){ //System.out.println("Exception :"+ e.getMessage()); } } } }Process.javapackage riu.cms7425.ProcessManagement; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; import javax.management.Query; import javax.swing.JOptionPane; public class Process { public ProcessControlBlock processInfo = new ProcessControlBlock(); //information of the pcb public void createProcess(){ int random = (int )(Math.random() * 50 + 1); processInfo.processId = random; String sizeProcess = (String )JOptionPane.showInputDialog(null, "Enter process size in kb : ", "Process Memory required",JOptionPane.QUESTION_MESSAGE); try{ processInfo.memoryRequired = Integer.parseInt(sizeProcess); } catch(NumberFormatException e){ JOptionPane.showMessageDialog(null, "Non-integer input, so default value is used", "Process Size", JOptionPane.ERROR_MESSAGE); } //processInfo.memoryAddress = & ; processInfo.ownerProcess = "null"; processInfo.parentProcessId = 0; processInfo.childProcessId = new int[0]; processInfo.priority = "High"; processInfo.processStatus = "new"; //processInfo. //process table create in it insert value... try{ // Create File Scanner fileInput=new Scanner(new File("Process Table.txt")); PrintWriter myFile=new PrintWriter(new FileOutputStream(new File("Process Table.txt"),true)); //myFile.println("Process ID , "+"Process status , "+"Process Memory , "+"Process Prority , "); myFile.println("\n"+processInfo.processId+" , "+processInfo.processStatus+" , "+processInfo.memoryRequired+" , "+processInfo.priority ); myFile.close(); }catch(FileNotFoundException e) { try{ PrintWriter myFile=new PrintWriter("Process Table.txt"); myFile.println("Process ID , "+"Process status , "+"Process Memory , "+"Process Prority"); myFile.println("\n"+processInfo.processId+" , "+processInfo.processStatus+" , "+processInfo.memoryRequired+" , "+processInfo.priority); myFile.close(); }catch(IOException ea){} } } void destoryProcess() { } public void suspendprocess(SchedulingQueue scQ) { try{ Process p = scQ.getProcessReadyQueue().poll(); p.processInfo.processStatus = "Suspend"; scQ.processSuspendQueue.add(p); JOptionPane.showMessageDialog(null, "process detail : " + p.getProcessInfo().getProcessId() +"\n state:" +p.getProcessInfo().getProcessStatus(), "Process info", JOptionPane.INFORMATION_MESSAGE); }catch(NullPointerException nullEx){ System.out.println("No process"); } } public void resumeProcess(SchedulingQueue scQ) { try{ Process p = scQ.getProcessSuspendQueue().poll(); p.processInfo.processStatus = "Ready"; scQ.processReadyQueue.add(p); JOptionPane.showMessageDialog(null, "process id : " + p.getProcessInfo().getProcessId() +"\n state:" +p.getProcessInfo().getProcessStatus(), "Process detail", JOptionPane.INFORMATION_MESSAGE); }catch(NullPointerException nullEx){ System.out.println("No process"); } } public void blockProcess(SchedulingQueue scQ) { try{ Process p = scQ.getProcessReadyQueue().poll(); p.processInfo.processStatus = "block"; scQ.processBlockQueue.add(p); JOptionPane.showMessageDialog(null, "process id : " + p.getProcessInfo().getProcessId() +"\n state:" +p.getProcessInfo().getProcessStatus(), "Process detail", JOptionPane.INFORMATION_MESSAGE); }catch(NullPointerException nullEx){ System.out.println("No process"); } } public void wakeUpProcess(SchedulingQueue scQ) { try{ Process p = scQ.getProcessBlockQueue().poll(); p.processInfo.processStatus = "Ready"; scQ.processReadyQueue.add(p); JOptionPane.showMessageDialog(null, "process id : " + p.getProcessInfo().getProcessId() +"\n state:" +p.getProcessInfo().getProcessStatus(), "Process detail", JOptionPane.INFORMATION_MESSAGE); }catch(NullPointerException nullEx){ System.out.println("No process"); } } public void DispatchProcess(SchedulingQueue scQ,int schedulingAlgorithm){ switch(schedulingAlgorithm){ case 0:{ try{ Process p = scQ.processReadyQueue.poll(); p.processInfo.processStatus = "Running"; System.out.println(p.getProcessInfo().getProcessId() + " "+p.getProcessInfo().getProcessMemory() + " "+p.getProcessInfo().getProcessStatus()); JOptionPane.showMessageDialog(null, "process id : " + p.getProcessInfo().getProcessId() +"\n state:" +p.getProcessInfo().getProcessStatus(), "Process detail", JOptionPane.INFORMATION_MESSAGE); }catch(NullPointerException nullEx){ System.out.println("No process"); } break; } case 1:{ try{ Process p = scQ.processReadyQueue.poll(); p.processInfo.processStatus = "Running"; System.out.println(p.getProcessInfo().getProcessId() + " "+p.getProcessInfo().getProcessMemory() + " "+p.getProcessInfo().getProcessStatus()); ProcessPage page = new ProcessPage(); page.pageCalculate(p); if(p.getProcessInfo().getProcessMemory() > page.getNumberofPageProcess() ){ p.processInfo.memoryRequired =p.getProcessInfo().getProcessMemory() - page.getPageSize() ; scQ.processReadyQueue.add(p); } JOptionPane.showMessageDialog(null, "process id : " + p.getProcessInfo().getProcessId() +"\n state:" +p.getProcessInfo().getProcessStatus(), "Process detail", JOptionPane.INFORMATION_MESSAGE); }catch(NullPointerException nullEx){ System.out.println("No process"); } break; } } } void changeProcessPriority(){} public void communicateOtherProcess(){ MyProcessthread th = new MyProcessthread(Integer.toString(processInfo.processId)); MyProcessthread th1 = new MyProcessthread(Integer.toString(processInfo.processId+1)); th.start(); th1.start(); } public ProcessControlBlock getProcessInfo(){ return processInfo; } }//end of public class Process ProcessControlBlock.java package riu.cms7425.ProcessManagement; //PCB class save the info of a particular process info public class ProcessControlBlock { public ProcessControlBlock(){ memoryRequired= 64; } protected int processId; protected String processStatus; protected String ownerProcess; protected int parentProcessId; protected int childProcessId[]; protected int memoryRequired; protected int memoryAddress; //Process parentProcess; //Process childProcess; protected String priority; class Resource{ }//end of class Resource class Register{ int a,b,c; int sum; }//end of class Register protected String ioDeviceStatus[]; //*************************************getter public int getProcessId(){ return processId; } public int getProcessMemory(){ return memoryRequired; } public String getProcessStatus(){ return processStatus; } //**************************************setter public void setProcessState(String state){ processStatus = state; } }//end of public class ProcessControlBlock ProcessPage.java package riu.cms7425.ProcessManagement; import java.io.File; import java.io.IOException; import java.util.Scanner; import javax.swing.JOptionPane; public class ProcessPage { private int pageSize; private int numberOfPages; public void pageCalculate(Process process){ // Read File pageSize = 4; try{ Scanner fileInput=new Scanner(new File("configuartion.txt")); while (fileInput.hasNextLine()) { String sReadFile = fileInput.nextLine(); String[] pageSizeGet = sReadFile.split(":"); pageSize = Integer.parseInt(pageSizeGet[1]); } fileInput.close(); }catch(IOException ioe){ JOptionPane.showMessageDialog(null, "file not found", "IOException", JOptionPane.ERROR_MESSAGE); } System.out.println(pageSize); int numberOfPages = process.getProcessInfo().memoryRequired/pageSize; if( process.getProcessInfo().memoryRequired % pageSize != 0){ //not complete divide then numberOfPages = numberOfPages +1; } System.out.println("number of pages are :"+ numberOfPages); JOptionPane.showMessageDialog(null, "Number of page created :"+ numberOfPages+ "\nPage size:" + pageSize, "Process Pages", JOptionPane.INFORMATION_MESSAGE); } //*******************************getter int getNumberofPageProcess(){ return numberOfPages; } int getPageSize(){ return pageSize; } } Resource.java package riu.cms7425.ProcessManagement; public class Resource { public Resource() { } //******name public String printer = "printer"; public String Scanner = "scanner"; public String monitor = "monitor"; public String keyboard = "Keyboard"; }
SchedulingQueue.java
package riu.cms7425.ProcessManagement; import java.util.LinkedList; import java.util.Queue; public class SchedulingQueue { public Queue<Process> processCreateQueue = new LinkedList<Process>(); public Queue<Process> processReadyQueue = new LinkedList<Process>(); public Queue<Process> processSuspendQueue = new LinkedList<Process>(); public Queue<Process> processBlockQueue = new LinkedList<Process>(); public Queue<Process> getProcessCreateQueue(){ return processCreateQueue; } public Queue<Process> getProcessReadyQueue(){ return processReadyQueue; } public Queue<Process> getProcessSuspendQueue(){ return processSuspendQueue; } public Queue<Process> getProcessBlockQueue(){ return processBlockQueue; } } ControlPanel.java //name: Farzam babar //CMS:- 7425 package riu.cms7425.GUI; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class ControlPanel { static JFrame mainWindow = new JFrame(); static JButton exitProgramButton = new JButton("Exit Program"); static JPanel buttonBox = new JPanel(new GridBagLayout()); public static void main(String[] args){ mainWindow.setTitle("FB operating system simulation - Control Panel"); mainWindow.setSize(550,550); mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); new MainMenu(); buttonBox.setVisible(true); exitProgramButton.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent event){ System.exit(0); }//end of button action });//end of button action listener buttonBox.add(exitProgramButton); mainWindow.add(buttonBox,BorderLayout.SOUTH); mainWindow.setVisible(true); }//end of public static void main(String[] args) }//end of public class ProgramManager MainMenu.java package riu.cms7425.GUI; import java.awt.*; import javax.swing.*; import riu.cms7425.ProcessManagement.SchedulingQueue; import java.awt.event.*; import java.io.IOException; import java.io.PrintWriter; public class MainMenu extends ControlPanel{ public JPanel menuPanel = new JPanel(new GridBagLayout()); JPanel headingPanel = new JPanel(); ButtonGroup radioButtonGroup; final int managementButtonSize = 4; JRadioButton managementButton[] = new JRadioButton[managementButtonSize]; String managementButtonName[] = {"Process management","Memory management","I/O device management", "Other Operation"}; JButton configuartionButton = new JButton("Configuaration buttion"); JTextArea pagesizetext; public MainMenu(){ GridBagConstraints arrangeButton = new GridBagConstraints(); JLabel meanHeading = new JLabel("Control Panel MENU"); meanHeading.setFont(new Font("Sarif",Font.BOLD+Font.ITALIC,25)); headingPanel.add(meanHeading); headingPanel.add(configuartionButton); configuartionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JFrame configuration_frame = new JFrame("Configuration"); configuration_frame.setSize(250,250); configuration_frame.setVisible(true); JLabel heading = new JLabel("Program Setting"); heading.setFont(new Font("Sarif",Font.BOLD+Font.ITALIC,25)); JPanel inputOptionsPanel = new JPanel(new GridLayout(1,1,5,5)); JLabel oneOptionPage = new JLabel("Page size"); pagesizetext = new JTextArea(1,5); inputOptionsPanel.add(oneOptionPage); inputOptionsPanel.add(pagesizetext); JButton saveButton = new JButton("save setting"); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try{ int size = Integer.parseInt(pagesizetext.getText().toString()); // Create File try{ PrintWriter myFile=new PrintWriter("configuartion.txt"); myFile.print("page size:"+pagesizetext.getText().toString()); myFile.close(); configuration_frame.setVisible(false); } catch(IOException eio ){ JOptionPane.showMessageDialog(null, "file not found", "IOException", JOptionPane.ERROR_MESSAGE); } }catch(NumberFormatException nue){ JOptionPane.showMessageDialog(null, "not number", "Input Error", JOptionPane.ERROR_MESSAGE); } } }); configuration_frame.add(heading,BorderLayout.NORTH); configuration_frame.add(inputOptionsPanel); configuration_frame.add(saveButton,BorderLayout.SOUTH); } }); arrangeButton.insets = new Insets(0,0,10,20); radioButtonGroup = new ButtonGroup(); radioButtonActionHandler eventHandler = new radioButtonActionHandler(); menuPanel.setBorder(BorderFactory.createLineBorder(Color.GRAY)); int y = 3; for(int i=0;i<managementButtonSize;i++) { arrangeButton.gridx = 0; arrangeButton.gridy = y; managementButton[i] = new JRadioButton(managementButtonName[i]); managementButton[i].setFont(new Font("Serif",Font.BOLD,25)); menuPanel.add(managementButton[i],arrangeButton); y =y+2; radioButtonGroup.add(managementButton[i]); managementButton[i].addActionListener(eventHandler); } mainWindow.add(headingPanel,BorderLayout.NORTH); mainWindow.add(menuPanel,BorderLayout.CENTER); }//end of constructor (public MainMenu()) public class radioButtonActionHandler implements ActionListener{ public void actionPerformed(ActionEvent event){ for(int i=0;i<managementButtonSize;i++) { if(event.getSource() == managementButton[i]) { menuPanel.setVisible(false); headingPanel.setVisible(false); switch(i) { case 0: { ProcessGUI process= new ProcessGUI(); process.ProcessGUIMenu(new SchedulingQueue()); break; }//end of case 0: case 1: case 2: case 3: { JLabel meanHeading = new JLabel(managementButtonName[i]); meanHeading.setFont(new Font("Sarif",Font.BOLD+Font.ITALIC,25)); headingPanel = new JPanel(); headingPanel.add(meanHeading); mainWindow.add(headingPanel,BorderLayout.NORTH); JLabel proMessage= new JLabel("In Progress"); proMessage.setFont(new Font("Sarif",Font.BOLD+Font.ITALIC,75)); mainWindow.add(proMessage,BorderLayout.CENTER); }//end of cases }//end of switch }//end of if(event.getSource() == managementButton[i]) }//end of for(int i=0;i<managementButtonSize;i++) }//end of public void actionPerformed(ActionEvent event) }//end of public class radioButtonActionHandler implements ActionListener }//end of public class MainMenu extends ProgramManager ProcessGUI.java package riu.cms7425.GUI; import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.LinkedList; import java.util.Queue; import riu.cms7425.ProcessManagement.Process; import riu.cms7425.ProcessManagement.ProcessPage; import riu.cms7425.ProcessManagement.SchedulingQueue; public class ProcessGUI extends ControlPanel{ JPanel processPanel = new JPanel(); JPanel headingPanel = new JPanel(); Box buttonBox = Box.createVerticalBox(); //for adjustment button JButton back; final int processButtonSize = 8; JButton processbutton[] = new JButton[processButtonSize]; String processButtonName[] = {" Create process "," resume process "," suspend process ", " block process "," wake up process "," dispatch process ", " priority process "," cummunicate process"}; ButtenEventHandler buttonHandle = new ButtenEventHandler(); //Queue<Process> processCreateQueue = new LinkedList<Process>(); Process process ; SchedulingQueue scQue = new SchedulingQueue(); /*public ProcessGUI(){ }*/ /*public ProcessGUI(){ ProcessGIl(); } public ProcessGUI(SchedulingQueue scQueArg) { scQue= scQueArg; ProcessGUIMenu(); //mainWindow.setVisible(true); }//end of public ProcessGUI() */ public void ProcessGUIMenu(SchedulingQueue scQueArg){ scQue = scQueArg; JLabel meanHeading = new JLabel("Process Management menu"); meanHeading.setFont(new Font("Sarif",Font.BOLD+Font.ITALIC,25)); headingPanel.add(meanHeading); back = new JButton("<< back"); headingPanel.add(back); back.addActionListener(buttonHandle); //back to mean menu.. buttonBox.setBorder(BorderFactory.createLineBorder(Color.GRAY)); for(int i=0;i<processButtonSize;i++) { processbutton[i] = new JButton(processButtonName[i]); //initialize the button and name it processbutton[i].setPreferredSize(new Dimension(165,25)); buttonBox.add(Box.createVerticalStrut(25)); //gape between button buttonBox.add(processbutton[i]); //add button in the panel processbutton[i].addActionListener(buttonHandle); //initialize action to each button }//end of for(int i=0;i<processButtonSize;i++) processPanel.add(buttonBox); mainWindow.add(headingPanel,BorderLayout.NORTH); mainWindow.add(processPanel,BorderLayout.CENTER); } public class ButtenEventHandler implements ActionListener{ public void actionPerformed(ActionEvent event){ if(event.getSource() == back){ processPanel.setVisible(false); headingPanel.setVisible(false); new MainMenu(); //display main Menu.. }//end of if(event.getSource() == back) if(event.getSource() == processbutton[0]) { process = new Process(); process.createProcess(); process.processInfo.setProcessState("Ready"); scQue.processReadyQueue.add(process); //**only for implementation check... JOptionPane.showMessageDialog(null, "process id : " + process.getProcessInfo().getProcessId() +"\n state:" +process.getProcessInfo().getProcessStatus(), "Process Detail", JOptionPane.INFORMATION_MESSAGE); ProcessPage page = new ProcessPage(); page.pageCalculate(process); } if(event.getSource() == processbutton[1]){ process = new Process(); process.resumeProcess(scQue); } if(event.getSource() == processbutton[2]){ process = new Process(); process.suspendprocess(scQue); } if(event.getSource() == processbutton[3]){ process = new Process(); process.blockProcess(scQue); } if(event.getSource() == processbutton[4]){ process = new Process(); process.wakeUpProcess(scQue); } if(event.getSource() == processbutton[5]){ processPanel.setVisible(false); headingPanel.setVisible(false); new SchedulingGUI(scQue); //process.DispatchProcess(scQue.getProcessReadyQueue(),0); } if(event.getSource() == processbutton[7]){ process = new Process(); process.communicateOtherProcess(); } /* for(int i = 1;i<processButtonSize;i++) { if(event.getSource() == processbutton[i]) { processPanel.setVisible(false); headingPanel.setVisible(false); JLabel btnName= new JLabel(processButtonName[i]); JLabel proMessage = new JLabel(", In Progress"); //JPanel p = new JPanel(); Box p = Box.createVerticalBox(); p.add(btnName); p.add(proMessage); btnName.setFont(new Font("Sarif",Font.ITALIC,50)); proMessage.setFont(new Font("Sarif",Font.ITALIC,45)); mainWindow.add(p,BorderLayout.CENTER); }//end of if(event.getSource() == processbutton[i]) }//end of for(int i = 0;i<processButtonSize;i++)*/ }//end of public void actionPerformed(ActionEvent event) }//end of inner class public class ButtenEventHandler implements ActionListener{ }//end of public class ProcessGUI extends ControlPanel{ SchedulingGUI.java package riu.cms7425.GUI; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.LinkedList; import java.util.Queue; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import riu.cms7425.ProcessManagement.Process; import riu.cms7425.ProcessManagement.SchedulingQueue; public class SchedulingGUI extends ProcessGUI{ JPanel schedulingHeadingPanel = new JPanel(); JButton backProcessMenuBtn; String[] buttonschedulingName = {"F.C.F.S (Queue)","Round Robin "} ; JButton[] schedulingButton = new JButton[2]; Box buttonBoxScheduling = Box.createVerticalBox(); //for adjustment button JPanel schedulingPanel = new JPanel(); SchedulingButtonHandler schedulingEventHandler = new SchedulingButtonHandler(); //Queue<Process> processQueue = new LinkedList<Process>(); int numSch; SchedulingQueue schedulingQGUI; public SchedulingGUI(SchedulingQueue queueArg){ schedulingQGUI = queueArg; JLabel schedulingHeading = new JLabel("Scheduling Menu"); schedulingHeading.setFont(new Font("Sarif",Font.BOLD+Font.ITALIC,25)); backProcessMenuBtn = new JButton("<<Back"); backProcessMenuBtn.addActionListener(schedulingEventHandler); schedulingHeadingPanel.add(schedulingHeading); schedulingHeadingPanel.add(backProcessMenuBtn); buttonBoxScheduling.setBorder(BorderFactory.createLineBorder(Color.GRAY)); for(int i=0;i<2;i++) { schedulingButton[i] = new JButton(buttonschedulingName[i]); //initialize the button and name it schedulingButton[i].setPreferredSize(new Dimension(165,25)); buttonBoxScheduling.add(Box.createVerticalStrut(25)); //gape between button buttonBoxScheduling.add(schedulingButton[i]); //add button in the panel schedulingButton[i].addActionListener(schedulingEventHandler); //initialize action to each button }//end of for(int i=0;i<processButtonSize;i++) schedulingPanel.add(buttonBoxScheduling); mainWindow.add(schedulingHeadingPanel,BorderLayout.NORTH); mainWindow.add(schedulingPanel,BorderLayout.CENTER); } class SchedulingButtonHandler implements ActionListener{ @Override public void actionPerformed(ActionEvent event) { if(event.getSource() == backProcessMenuBtn){ schedulingPanel.setVisible(false); schedulingHeadingPanel.setVisible(false); ProcessGUI p = new ProcessGUI(); p.ProcessGUIMenu(schedulingQGUI); } if(event.getSource() == schedulingButton[0]){ process = new Process(); process.DispatchProcess(schedulingQGUI, 0); } if(event.getSource() == schedulingButton[1]){ process = new Process(); process.DispatchProcess(schedulingQGUI, 1); } } } }
yr bro yehi c++ ma mil skta h kia
ReplyDelete