王朝知道
分享
 
 
 

进程管理 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.

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
如何用java替换看不见的字符比如零宽空格​十六进制U+200B
 干货   2023-09-10
网页字号不能单数吗,网页字体大小为什么一般都是偶数
 干货   2023-09-06
java.lang.ArrayIndexOutOfBoundsException: 4096
 干货   2023-09-06
Noto Sans CJK SC字体下载地址
 干货   2023-08-30
window.navigator和navigator的区别是什么?
 干货   2023-08-23
js获取referer、useragent、浏览器语言
 干货   2023-08-23
oscache遇到404时会不会缓存?
 干货   2023-08-23
linux下用rm -rf *删除大量文件太慢怎么解决?
 干货   2023-08-08
刀郎新歌破世界纪录!
 娱乐   2023-08-01
js实现放大缩小页面
 干货   2023-07-31
生成式人工智能服务管理暂行办法
 百态   2023-07-31
英语学习:过去完成时The Past Perfect Tense举例说明
 干货   2023-07-31
Mysql常用sql命令语句整理
 干货   2023-07-30
科学家复活了46000年前的虫子
 探索   2023-07-29
英语学习:过去进行时The Past Continuous Tense举例说明
 干货   2023-07-28
meta name="applicable-device"告知页面适合哪种终端设备:PC端、移动端还是自适应
 干货   2023-07-28
只用css如何实现打字机特效?
 百态   2023-07-15
css怎么实现上下滚动
 干货   2023-06-28
canvas怎么画一个三角形?
 干货   2023-06-28
canvas怎么画一个椭圆形?
 干货   2023-06-28
canvas怎么画一个圆形?
 干货   2023-06-28
canvas怎么画一个正方形?
 干货   2023-06-28
中国河南省郑州市金水区蜘蛛爬虫ip大全
 干货   2023-06-22
javascript简易动态时间代码
 干货   2023-06-20
感谢员工的付出和激励的话怎么说?
 干货   2023-06-18
 
>>返回首页<<
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有