当前位置:文档之家› 东北大学秦皇岛分校操作系统课设报告

东北大学秦皇岛分校操作系统课设报告

东北大学秦皇岛分校计算机与通信工程学院计算机操作系统课程设计设计题目:进程管理器专业名称计算机科学与技术班级学号xxxx学生姓名xxxx指导教师xxxxx设计时间2014-12-29~2015-1-15课程设计任务书专业:计算机科学与技术学号:学生姓名(签名):设计题目1、高优先权调度算法的模拟2、进程管理器的模拟实现二、主要内容1、目的:编程模拟实现进程管理器,加深对进程、程序概念掌握. 2、进程管理器主界面如下:(1)源代码:<1> Form1.csusing System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Management;using System.Diagnostics;namespace WindowsApplication1{public partial class Form1 : Form{public Form1(){InitializeComponent();this.listProcesses.MultiSelect = false;this.listProcesses.View = View.Details;this.listProcesses.Columns.Add("pname",(int)CreateGraphics().MeasureString("aaaaaaaaaaaaaaaaaaaaaa",Font).Width);this.listProcesses.Columns.Add("pID", (int)CreateGraphics().MeasureString("000000000000", Font).Width);this.listProcesses.Columns.Add("username", (int)CreateGraphics().MeasureString( "aaaaaaaaaaaaaaaaaaaaa", Font).Width);this.listProcesses.Columns.Add("priority", (int)CreateGraphics().MeasureString( "aaaaaaaaa", Font).Width);this.listProcesses.Columns.Add("Memory usage", (int)CreateGraphics().MeasureString("000000000000000",Font).Width);}private void Form1_Load(object sender, EventArgs e){RefreshList();}private void RefreshList(){Process[] processes;processes = Process.GetProcesses();this.listProcesses.Items.Clear();foreach (Process instance in processes){ListViewItem lvi = new ListViewItem(instance.ProcessName);lvi.SubItems.Add(FormatProcessID(instance.Id));lvi.SubItems.Add(GetProcessUserName(instance.Id));lvi.SubItems.Add(instance.BasePriority.ToString());lvi.SubItems.Add(FormatMemorySize(instance.WorkingSet64));string strToolTip = null;ProcessModuleCollection modules;if (pareTo("System") != 0 || pareTo("Idle") != 0){try{////当进程不充允枚举模块时会产生异常modules = instance.Modules;foreach (ProcessModule aModule in modules){strToolTip += aModule.ModuleName;strToolTip += "; ";}}catch (ponentModel.Win32Exception){}}lvi.ToolTipText = strToolTip;this.listProcesses.Items.Add(lvi);}}//格式化内存字符串private string FormatMemorySize(long lMemorySize){return String.Format("{0,8:N0} K", lMemorySize / 1000);}private string FormatProcessID(int id){return String.Format("{0,8}",id);}private static string GetProcessUserName(int pID){string text1 = null;SelectQuery query1 =new SelectQuery("Select * from Win32_Process WHERE processID=" + pID);ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(query1);try{foreach (ManagementObject disk in searcher1.Get()){ManagementBaseObject inPar = null;ManagementBaseObject outPar = null;inPar = disk.GetMethodParameters("GetOwner");outPar = disk.InvokeMethod("GetOwner", inPar, null);text1 = outPar["User"].ToString();break;}}catch{text1 = "SYSTEM";}return text1;}private void StopProcess_Click(object sender, EventArgs e){Process process = Process.GetProcessById(int.Parse(this.listProcesses.SelectedItems[0].SubItems[1].Text));process.Kill();RefreshList(); //释放进程的资源}private void Refresh_Click(object sender, EventArgs e){RefreshList();}private void CreateProcess_Click(object sender, EventArgs e){DialogBox dlg = new DialogBox();if (dlg.ShowDialog() == DialogResult.OK){try{Process.Start(dlg.FileName);}catch (ponentModel.Win32Exception){MessageBox.Show(String.Format("can't find the files '{0}',please make sure of the name of files then try again。

\n press [start] to search files",dlg.FileName));}}}}}<2> Form1.Designer.csnamespace WindowsApplication1{partial class Form1{/// <summary>/// 必需的设计器变量。

/// </summary>private ponentModel.IContainer components = null;/// <summary>/// 清理所有正在使用的资源。

/// </summary>/// <param name="disposing">如果应释放托管资源,为 true;否则为false。

</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// <summary>/// 设计器支持所需的方法/// 使用代码编辑器修改此方法的内容。

/// </summary>private void InitializeComponent(){this.listProcesses = new System.Windows.Forms.ListView(); this.StopProcess = new System.Windows.Forms.Button();this.btnRefresh = new System.Windows.Forms.Button();this.CreateProcess = new System.Windows.Forms.Button();this.SuspendLayout();//// listProcesses//this.listProcesses.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.Anchor Styles.Top | System.Windows.Forms.AnchorStyles.Bottom)| System.Windows.Forms.AnchorStyles.Left)| System.Windows.Forms.AnchorStyles.Right)));this.listProcesses.Location = new System.Drawing.Point(-1, 10); = "listProcesses";this.listProcesses.ShowItemToolTips = true;this.listProcesses.Size = new System.Drawing.Size(363, 297);this.listProcesses.TabIndex = 0;eCompatibleStateImageBehavior = false;//// StopProcess//this.StopProcess.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorSt yles.Bottom | System.Windows.Forms.AnchorStyles.Right)));this.StopProcess.Location = new System.Drawing.Point(274, 313); = "StopProcess";this.StopProcess.Size = new System.Drawing.Size(100, 23); this.StopProcess.TabIndex = 1;this.StopProcess.Text = "StopProcess";eVisualStyleBackColor = true;this.StopProcess.Click += new System.EventHandler(this.StopProcess_Click);//// btnRefresh//this.btnRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorSt yles.Bottom | System.Windows.Forms.AnchorStyles.Left)));this.btnRefresh.Location = new System.Drawing.Point(12, 313); = "btnRefresh";this.btnRefresh.Size = new System.Drawing.Size(75, 23);this.btnRefresh.TabIndex = 2;this.btnRefresh.Text = "Reflesh(&R)";eVisualStyleBackColor = true;this.btnRefresh.Click += new System.EventHandler(this.Refresh_Click);//// CreateProcess//this.CreateProcess.Anchor = System.Windows.Forms.AnchorStyles.Bottom;this.CreateProcess.Location = new System.Drawing.Point(141, 313); = "CreateProcess";this.CreateProcess.Size = new System.Drawing.Size(100, 23); this.CreateProcess.TabIndex = 3;this.CreateProcess.Text = "CreateProcess";eVisualStyleBackColor = true;this.CreateProcess.Click += new System.EventHandler(this.CreateProcess_Click);//// Form1//this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(364, 344);this.Controls.Add(this.CreateProcess);this.Controls.Add(this.btnRefresh);this.Controls.Add(this.StopProcess);this.Controls.Add(this.listProcesses); = "Form1";this.Text = " Process Manager";this.Load += new System.EventHandler(this.Form1_Load);this.ResumeLayout(false);}#endregionprivate System.Windows.Forms.ListView listProcesses; private System.Windows.Forms.Button StopProcess;private System.Windows.Forms.Button btnRefresh;private System.Windows.Forms.Button CreateProcess;}}<3> DialogBox.csusing System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication1{public partial class DialogBox : Form{public DialogBox(){InitializeComponent();StartPosition = FormStartPosition.CenterParent;bel1.Text = "open file...";}private void DialogBox_Load(object sender, EventArgs e){}private void OK_Click(object sender, EventArgs e){DialogResult = DialogResult.OK;}private void Cancel_Click(object sender, EventArgs e){DialogResult = DialogResult.Cancel;}private void btnShow_Click(object sender, EventArgs e){OpenFileDialog dlg = new OpenFileDialog();dlg.Filter = "program|*.exe|" + "all files|*.*";if (dlg.ShowDialog() == DialogResult.OK){boBox1.Text = dlg.FileName;}}public string FileName{get{return boBox1.Text;}}}}<4> DialogBox.Designer.csnamespace WindowsApplication1{partial class DialogBox{/// <summary>/// 必需的设计器变量。

相关主题