Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS470 Lab3 TA Notes. Step 1 This is just a simple program that reads in from the command line the time the program should run.

Similar presentations


Presentation on theme: "CS470 Lab3 TA Notes. Step 1 This is just a simple program that reads in from the command line the time the program should run."— Presentation transcript:

1 CS470 Lab3 TA Notes

2 Step 1 This is just a simple program that reads in from the command line the time the program should run.

3 Step 2 Do not create a new program Modify the program from Step 1 Each new background process should be opened in its own console Use the sample background program in the book on page 249 to create the background programs

4 Step 2 cont. Each background program should allow the user to terminate it. Ensure that handles of all processes and handle are closed at the end of the program

5 Step 3 Again do not create a new program Modify the program from Step 2 Use a waitable timer to terminate all processes if not terminated by the user You will either need to write a function to convert user time given into machine time or read about quitTime and Quadpart in the MSDN library

6 Lab Environment

7 For all labs use #define _WIN32_WINNT 0x0500 at the top of your code somewhere instead of where the book says to add /D _WIN32_WINNT=0x400 as a compiler flag.

8 New notes 2006: Lab 3 Part A Usage example: U:\>lab3a The integer represents the time the program waits. Pseudo-code: main : args make sure there are 2 arguments, one of which is an integer that is greater than -1 create a waitable timer, assigning it to a handle set the timer wait for timer to complete clean up handle exit Remarks: The book uses weird code to set LARGE_INTEGER quitTime. Use quitTimer.QuadPart = -10000000 * atoi( argv[ 1 ] ); Then pass quitTimer to SetWaitableTimer like how it is in the book.

9 New notes 2006: Lab 3 Part B Usage example: U:\>lab3b The integer represents the number of processes it should spawn. Pseudo-code: main : args make sure there are 2 arguments, one of which is an integer that is greater than -1 for integer from command line create a process that spawns an external program exit Remarks: It is advisable to use the program from part A and modify it a bit as the external program that part B spawns as it essentially does what you need.

10 New notes 2006: Lab 3 Part B To pass a command line string to CreateProcess, set up a char array as the program name and a space. Then use strcat and itoa to append a number if need be. Remember to always Zeromemory() and related before CreateProcess() if you're reusing the startupInfo variable.

11 New notes 2006: Lab 3 Part C Usage example: U:\>lab3c Integer1 - The number of seconds you want the controlling process to run for. Integer2 - The number of processes to spawn. Pseudo-code: main : args make sure there are 3 arguments, the last two being integers that are greater than -1 for the first command line integer create a process that spawns an external program add the process to a handle table create a waitable timer set the timer wait for the timer to expire for each handle in handle table terminate process associated with the handle clean up handles

12 New notes 2006: Lab 3 Part C Remarks: The for loop for creating processes should look nearly similar to the one in part B. The setting up and waiting of the waitable timer should look nearly similar to the one in part A. To kill processes, you need an array of handles. In the for loop that creates the process you notice that you're passing a reference to processInfo. While in the loop, processInfo.hProcess is the handle associated with the process you create. Add that the handle array. Then in the loop where you kill processes you can use TerminateProcess as it's found in the book. Remember to always Zeromemory() and related before CreateProcess() if you're reusing the startupInfo variable. Email TA if you have questions. Always try to explain the problem as thoroughly as possible. Attach code. Refer to the code and line numbers in your email.


Download ppt "CS470 Lab3 TA Notes. Step 1 This is just a simple program that reads in from the command line the time the program should run."

Similar presentations


Ads by Google