分享
 
 
 

进程管理 os编程

王朝知道·作者佚名  2009-09-02
窄屏简体版  字體: |||超大  
 
分類: 電腦/網絡 >> 程序設計 >> 其他編程語言
 
問題描述:

实验一 进程管理

一、实验目的:

(1)通过本次实验,进一步理解进程PCB的概念,以及PCB如何实现,复习数据结构中如何对链的操作,包括建链、删除、插入结点等。

(2)通过实验使学生进一步了解进程、进程状态、进程控制块等基本概念。

二、实验要求:

(1)复习进程管理部分内容。

(2)运行示例程序,进一步明确实验要求。

(3)上机编程,调试程序。

三、实验内容:

(1)建立一个结点,即PCB块包括用户标识域、状态域(执行、等待、就绪)、link域。

(2)建立三个队列(执行队列、就绪队列、等待队列)。

(3)根据进程状态转换实现对三个队列的具体操作。

(4)运行结果。

參考答案:

创建进程的api函数

BOOL CreateProcess(

LPCWSTR pszImageName,

LPCWSTR pszCmdLine,

LPSECURITY_ATTRIBUTES psaProcess,

LPSECURITY_ATTRIBUTES psaThread,

BOOL fInheritHandles,

DWORD fdwCreate,

LPVOID pvEnvironment,

LPWSTR pszCurDir,

LPSTARTUPINFOW psiStartInfo,

LPPROCESS_INFORMATION pProcInfo

);

Parameters

pszImageName

[in] Pointer to a null-terminated string that specifies the module to execute.

The string can specify the full path and filename of the module to execute or it can specify a partial path and filename.

The lpszImageName parameter must be non-NULL and must include the module name.

pszCmdLine

[in, out] Pointer to a null-terminated string that specifies the command line to execute.

The system adds a null character to the command line, trimming the string if necessary, to indicate which file was used.

The lpszCmdLine parameter can be NULL. In that case, the function uses the string pointed to by lpszImageName as the command line.

If lpszImageName and lpszCmdLine are non-NULL, * lpszImageName specifies the module to execute, and * lpszCmdLine specifies the command line.

C runtime processes can use the argc and argv arguments.

If the filename does not contain an extension, .EXE is assumed.

If the filename ends in a period (.) with no extension, or if the filename contains a path, .EXE is not appended.

psaProcess

[in] Not supported; set to NULL.

psaThread

[in] Not supported; set to NULL.

fInheritHandles

[in] Not supported; set to FALSE.

fdwCreate

[in] Specifies additional flags that control the priority and the creation of the process.

The following creation flags can be specified in any combination, except as noted.

Value Description

CREATE_DEFAULT_ERROR_MODE Not supported.

CREATE_NEW_CONSOLE The new process has a new console, instead of inheriting the parent's console.

CREATE_NEW_PROCESS_GROUP Not supported.

CREATE_SEPARATE_WOW_VDM Not supported.

CREATE_SHARED_WOW_VDM Not supported.

CREATE_SUSPENDED The primary thread of the new process is created in a suspended state, and does not run until the ResumeThread function is called.

CREATE_UNICODE_ENVIRONMENT Not supported.

DEBUG_PROCESS If this flag is set, the calling process is treated as a debugger, and the new process is a process being debugged. Child processes of the new process are also debugged.

The system notifies the debugger of all debug events that occur in the process being debugged.

If you create a process with this flag set, only the calling thread (the thread that called CreateProcess) can call the WaitForDebugEvent function.

DEBUG_ONLY_THIS_PROCESS If this flag is set, the calling process is treated as a debugger, and the new process is a process being debugged. No child processes of the new process are debugged.

The system notifies the debugger of all debug events that occur in the process being debugged.

DETACHED_PROCESS Not supported.

INHERIT_CALLER_PRIORITY If this flag is set, the new process inherits the priority of the creator process.

Windows CE does not support the concept of a priority class. The priority of a thread is the only parameter that determines a thread's scheduling priority.

pvEnvironment

[in] Not supported; set to NULL.

pszCurDir

[in] Not supported; set to NULL.

psiStartInfo

[in] Not supported; set to NULL.

pProcInfo

[out] Pointer to a PROCESS_INFORMATION structure that receives identification information about the new process.

Return Values

Nonzero indicates success.

Zero indicates failure.

To get extended error information, call GetLastError.

Remarks

In addition to creating a process, it also creates a thread object.

The size of the initial stack for the thread is described in the image header of the specified program's executable file.

The thread begins execution at the image's entry point.

The new process and the new thread handles are created with full access rights. For either handle, the handle can be used in any function that requires an object handle to that type.

The process is assigned a 32-bit process identifier. The identifier is valid until the process terminates. It can be used to identify the process, or specified in the OpenProcess function to open a handle to the process.

The initial thread in the process is also assigned a 32-bit thread identifier. The identifier is valid until the thread terminates and can be used to uniquely identify the thread within the system. These identifiers are returned in the PROCESS_INFORMATION structure.

The following list shows the directories indicated by the pszImageName parameter in the order that Windows CE searches them:

The windows (\windows) directory

The root (\) directory of the device

An OEM-dependent directory, which include the Windows CE Debug shell directory for Platform Builder users only

The following list shows the directories indicated by the pszImageName parameter in the order that Windows CE 2.10 and later search them:

The windows (\windows) directory

The root (\) directory of the device

An OEM-dependent directory

The OEM-defined shell (\ceshell) directory (Platform Builder users only)

The following list shows the directories indicated by the pszImageName parameter in the order Windows CE 1.0 through 2.01 search them:

The root of the PC Card, if it exists

The windows (\windows) directory

The root (\ ) directory of the device

When specifying an application name in the pszImageName string, it does not matter whether the application name includes the filename extension.

Do not call CreateProcess from a DllMain function. This causes the application to stop responding.

The following registry subkey specifies a search path to use with the LoadLibrary function and CreateProcess:

HKEY_LOCAL_MACHINE\Loader

"SystemPath" = multi_sz:"\\path1\\"

"\\path2\\"

For efficiency, the path is searched before CESH but after the ROM and built in file systems. The path is only searched if the path of the file being looked for is not explicitly specified.

If the length of the SystemPath value exceeds 260 characters, the path is ignored. A change to the SystemPath key does not take effect until a Windows CE-based device is reset.

ExitThread, CreateThread, and a process that is starting (as the result of a call by CreateProcess) are serialized between each other within a process. Only one of these events can happen in an address space at a time. The following list shows the restrictions during the process:

During process startup and DLL initialization routines, new threads can be created but they do not begin execution until DLL initialization is completed.

In a process, only one thread at a time can be in a DLL initialization or detach routine.

The created process remains in the system until all threads within the process are terminated and all handles to the process and its threads are closed through calls to CloseHandle.

The handles for the process and the main thread must be closed through calls to CloseHandle. If these handles are not needed, close them immediately after the process is created.

The following events occur when the last thread in a process terminates:

All objects opened by the process are implicitly closed.

The process's termination status, which is returned by GetExitCodeProcess, changes from its initial value of STILL_ACTIVE to the termination status of the last thread to terminate.

The thread object of the main thread is set to the signaled state, satisfying threads that were waiting on the object.

The process object is set to the signaled state, satisfying threads that were waiting on the object.

The handle returned by the CreateProcess function has PROCESS_ALL_ACCESS access to the process object.

Requirements

OS Versions: Windows CE 1.0 and later.

Header: Winbase.h.

Link Library: Coredll.lib.

创建线程的api函数

HANDLE CreateThread(

LPSECURITY_ATTRIBUTES lpsa,

DWORD cbStack,

LPTHREAD_START_ROUTINE lpStartAddr,

LPVOID lpvThreadParam,

DWORD fdwCreate,

LPDWORD lpIDThread

);

Parameters

lpsa

[in] Ignored. Must be NULL.

cbStack

[in] Ignored unless the STACK_SIZE_PARAM_IS_A_RESERVATION flag is used; in that case the cbStack parameter specifies the virtual memory reserved for the new thread.

When ignored, the default stack size for a thread is determined by the linker setting /STACK.

lpStartAddr

[in] Long pointer to the application-defined function of type LPTHREAD_START_ROUTINE to be executed by the thread; represents the starting address of the thread. For more information on the thread function, see ThreadProc.

Note It is invalid to set lpStartAddr to NULL. If this value is passed in the parameter, the function will return ERROR_INVALID_PARAMETER.

lpvThreadParam

[in] Long pointer to a single 32-bit parameter value passed to the thread.

fdwCreate

[in] Specifies flags that control the creation of the thread.

The following table shows the values for this parameter.

Value Description

CREATE_SUSPENDED The thread is created in a suspended state and does not run until the ResumeThread function is called.

The thread can be run immediately after creation if the flag is not specified.

STACK_SIZE_PARAM_IS_A_RESERVATION The cbStack parameter specified the maximum stack size instead of being ignored.

This is a Windows CE only flag for the CreateThread function and is used to reserve the stack size for the thread created.

By default, a thread is created with 64 KB stack reserved. You can use this flag to increase the stack size for the new thread that was created.

lpIDThread

[out] Long pointer to a 32-bit variable that receives the thread identifier.

If this parameter is NULL, the thread identifier is not returned.

Return Values

A handle to the new thread indicates success.

NULL indicates failure.

To get extended error information, call GetLastError.

Remarks

The number of threads a process can create is limited by the available virtual memory and depends on the default stack size.

If every thread has 1 MB of stack space, you can create a maximum of 32 threads.

If you reduce the default stack size, you can create more threads.

Your application will perform better if you create one thread per processor and build queues of requests for which the application maintains the context information. That is because a thread processes all requests in a queue before processing requests in the next queue.

The new thread handle is created with THREAD_ALL_ACCESS to the new thread. The handle can be used in any function that requires a thread object handle.

Thread execution begins at the function specified by the lpStartAddr parameter. If this function returns, the DWORD return value is used to terminate the thread in an implicit call to the ExitThread function. Use the GetExitCodeThread function to get the thread's return value.

If the start address is invalid when the thread runs, an exception occurs, and the thread terminates. Thread termination due to a invalid start address is handled as an error exit for the thread's process. This behavior is similar to the asynchronous nature of CreateProcess, where the process is created even if it refers to invalid or missing .dll files.

The thread is created with a thread priority of THREAD_PRIORITY_NORMAL.

Use the GetThreadPriority and SetThreadPriority functions to get and set the priority value of a thread.

When a thread terminates, the thread object attains a signaled state, satisfying threads that were waiting on the object.

The thread object remains in the system until the thread has terminated and all handles to it are closed through a call to CloseHandle.

The ExitThread function, CreateThread function, and a process that is starting (as the result of a call by CreateProcess) are serialized between each other within a process. Only one of these events can happen in an address space at a time.

The following list shows the restrictions during the process:

During process startup and DLL initialization routines, threads can be created, but they do not begin execution until DLL initialization is done for the process.

In a process, only one thread at a time can be in a DLL initialization or detach routine.

Requirements

OS Versions: Windows CE 1.01 and later.

Header: Winbase.h.

Link Library: Coredll.lib.

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有