Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to create and delete a new process on Windows OS. IN C++ ONLY ha

ID: 639902 • Letter: W

Question

Write a program to create and delete a new process on Windows OS. IN C++ ONLY

have headers at the start of every module/ subroutine/ function which you have written to explain the inputs, outputs and function of the module. You should have a comment on every data item explaining what it is about. (Almost) every line of code should have a comment explaining what is going on. A comment such as /* Add 1 to counter */ will not be sufficient. The comment should explain what is being counted.

Background

1. CreatProcess( )

In Windows, one process can create another process by using the Win32 API function CreateProcess( ). Whenever a process is created, the OS performs a large amount of work such as allocating resources to the process, and creating a base thread for the process, etc.

The CreateProcess( ) function has many parameters, and some of them can be quite complex. Unlike the fork( ) call, which has no parameters and child

Explanation / Answer

The first process uses the CreateMutex() function to create the mutex object. Note that the function succeeds even if there is an existing object with the same name.

    // for WinXp

    #define _WIN32_WINNT 0x0501

    #include <windows.h>

    #include <stdio.h>

   

    int main()

    {

    // one process creates the mutex object.

    HANDLE hMutex;

    char * MName = "MyMutex";

   

    hMutex = CreateMutex(

        NULL,        // no security descriptor

        FALSE,     // mutex not owned

        MName);   // object name

   

    if (hMutex == NULL)

        printf("CreateMutex(): error: %d. ", GetLastError());

    else

    {

        if (GetLastError() == ERROR_ALREADY_EXISTS)

           printf("CreateMutex(): opened existing %s mutex. ", MName);

        else

           printf("CreateMutex(): new %s mutex successfully created. ", MName);

    }

   

     return 0;

    }

    

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote