Introduction
The simplest definition of Process is executing instance of an application. The process contains at least one thread. The thread is a fundamental unit of the operating system. Windows is a multitasking operating system. Every process contains at least one thread. Windows NT family system and Windows 95/98 based system support preemptive multitasking. So, we can work freely for multiple threads and multiple processors.
Process
Class
In Microsoft .NET framework all the namespaces derived from Object
. The System.Diagnostics
namespace provides the information about the process state, start the new process, etc. In this namespace allows to starts the new process, kill process, etc.
In process class allows to monitor local system process information or remote system process information. We also interact with the ProcessThread
and ProcessModule
classes. The ProcessStartup
class provides the arguments passing and etc. ProcessStartInfo
Constructor use to initializes the process information.
ProcessStartInfo
contains the following properties.
Arguments
The arguments property use to set the argument in file name like ShellExecute
function.
Filename
The FileName
Property is used to set the application name . We can set this property before starting the process class.
UseShellExecute
If we set this is True
we can perform the file operations (like, printing the contents in that file). If we set False
we just execute the application.
WindowStyle
We set and get the WindowStyle
in process starting time.
WaitForExit
WaitForExit
property is to wait for the process fora specified time.
For Example :-
Notepad->waitForExit(1000)
Kill
Kill
property is to kill the currently running process.
Ex :- notePad->Kill();
The following code is to start the notepad. It waits 1000 secounds and kills it automatically using kill property in Process
class.
Process *notePad = new Process();
notePad->StartInfo->FileName = "notepad.exe";
notePad->StartInfo->Arguments = "textfile.txt";
notePad->Start();
notepad->waitForExit(1000);
notepad->Kill();
Process Thread Class
The Process Thread contains information about the currently running process. We control the threads within the process. We set or get the thread proprieties like low, high. The Process Thread class contains the following properties.
BasePriority
The BasePrority is
used to get the priority.
CurrentPriority
The CurrentPriority
Class is to get the current priority
PriorityLevel
The PriorityLevel
is to Get or set the priority level
ThreadState
The ThreadState
is to get the current state
ProcessModule
class
The ProcessModule
class is to get the information about the process module. In ProcessModule
class, properties are used to get the information like get module name, memory size in the module, etc.
The following code explains the use of ProcessModule
class to get module name, fileinfo etc.
Process *notePad = new Process();
notePad->StartInfo->FileName = "notepad.exe";
notePad->StartInfo->Arguments = "selvam.txt";
notePad->Start();
System::Threading::Thread::Sleep(1000);
ProcessModule *myProcessModule;
myProcessModule = notePad->MainModule;
String *strFileName, *strModuleName;
int nMemory;
strFileName = myProcessModule->FileName;
strModuleName = myProcessModule->ModuleName;
nMemory = myProcessModule->ModuleMemorySize;
Conclusion
The .NET framework is used to simplify the programming model. So, we can easily interact with the operating system. The Process
class is useful to start the new process, stop the existing process and control the process. ProcessModule
class is used to get the module information in the running application.