头文件路径
linux 下引用C、C++标准库、其他库的头文件一般都在:
- /usr/include
- /usr/local/include
- /usr/lib/gcc-lib/xxx/xxx/include
macOS 上的头文件、库文件都被 XCode 接管了,也就是说不安装 XCode 很多开发都是做不了的,安装了 XCode 后一切都妥妥的。
开发通用的头文件都在这里:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
很多库在这里:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
Frameworks 里面基本都有 Headers 文件夹,也是些头文件,和 include里的基本相同
实验一
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
using namespace std;
int main() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
"C:\\Users\\xxx\\Desktop\\childProcess.exe", // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return -1;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}
#include <iostream>
#include <thread>
#include <windows.h>
using namespace std;
int main() {
printf("child process begins\n");
Sleep(5000);
printf("child process ends\n");
return 0;
}
实验二
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
using namespace std;
int main() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
"C:\\Users\\DJN\\Desktop\\childProcess.exe", // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return -1;
}
// Wait until child process exits.
// WaitForSingleObject( pi.hProcess, INFINITE );
Sleep(3000);
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}
实验三
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <synchapi.h>
using namespace std;
BOOL KillProcess(DWORD ProcessId) {
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, ProcessId);
if (hProcess == NULL) {
return FALSE;
}
if (!TerminateProcess(hProcess, 0)) {
return FALSE;
}
return TRUE;
}
int main() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
"C:\\Users\\DJN\\Desktop\\childProcess.exe", // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return -1;
}
// Wait until child process exits.
// WaitForSingleObject( pi.hProcess, INFINITE );
Sleep(3000);
DWORD dwPid = GetProcessId(pi.hProcess);
if (KillProcess(dwPid)) {
puts("Success");
} else {
puts("Error");
}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}