Q Including the initial parent process, how many processes are created by the pr
ID: 3822677 • Letter: Q
Question
Q Including the initial parent process, how many processes are created by the program shown in Figure 3.32? SHOW YOUR WORK, no points otherwise.
#include #include windows.h> int main (voID) STARTUPINFO si; PROCESS INFORMATION pi; allocate memory Zero Memory G&si;, sizeof (si)) si cb sizeof (si) Zero Memory C, sizeof (pi)) create child process if CreateProcess (NULL, use command line C:WINDOWS\system32\mspaint exe Command NULL, don't inherit process handle NULL, don't inherit thread handle FALSE, disable handle inheritance 0, no creation flags NULL, use parent's environment block NULL, use parent's existing directory &si; )) fprintf (stderr, Create Process Failed") return -1; parent will wait for the child to complete WaitForSingleObject Cpi.hProcess, INFINITE) printf ("Child Complete"); close handles Close Handle (poi hProcess); CloseHandle (pi.hThread);Explanation / Answer
In the above program we use startupinfo si(name of the variable)
first we have to know what is startupinfo...
startupinfo: The startupinfo structure contains information which is used to control how the process behaves and appears on startup. The startupinfo structure has no less than 18 fields.
ZeroMemory simply fills the memory of the struct with 0's, what essentially means that every value of the struct is set to 0..
child thread is created if it executes the if condtion successfully....
ZeroMemory does what it says. Here it's being used as a short hand way of setting all member of the structures to zero. In the case of STARTUPINFO, the cb member (count bytes) is then being set to its size (in bytes).
(The Windows API uses the cb trick a lot. It's how they spot which version of a structure you're using. New versions of a structure can have more members.)
Executable have a .exe extension in Windows. CreateProcess might be too stupid to realize you mean "mspaint.exe" when you type just "mspaint".
(At the command line, when you type just "mspaint" then the system will try to run mspaint.com, then mspaint.exe, then mspaint.bat, ... in the order of the extensions defined by the PATHEXT environment variable)
To get the error code when CreateProcess fails, call GetLastError() -- this is used by most of the WIN32 API which return a handle, pointer, BOOL, ...
You should have a good read of the comments for the CreateProcess in its MSDN entry!!
after successful execution of if one child thread is created....
one is parent and another one is child thread ....
so only one process it creates a child thread....
and last it checks if child is completed or not and waits until child completes...
last close the process and thread...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.