把自己的pid写入到文件pidfile
B通过读取该文件获取A进程的pid
要用到A的pid,一般都是衡咐写文件的
#include <首纯含sys/types.h>#include <裤亏unistd.h>
int main(void)
{
int i=2
pid_t pid
while(i--){
if((pid=fork())<0){
err_sys("fork error\n")
exit(1)
}
else if(pid==0){
printf("Child Thread: my pid is %d.\者笑n",getpid())
break
}else{
printf("Parent Thread: create thread, pid is %d.\n",pid)
}
}
exit(0)
}
HRESULThresVARIANT vInst_
hres = pObject->Get(L"TargetInstance", 0, &vInst_, 0, 0)
if(FAILED(hres))
{
cout <<"Failed to get TargetInstance: "<<hres <<endl
continue
}//if
try
{
_variant_t vInst
vInst.Attach(vInst_)// use C++ class to manage VARIANT
IWbemClassObjectPtr pWin32ProcessObj(vInst)
VARIANT vVar
hres = pWin32ProcessObj->Get(L"ExecutablePath", 0, &vVar, 0, 0)
if(FAILED(hres))
{
cout <<"Failed to get ExecutablePath: "<<hres <滑银<endl
}//if
else
{
_variant_t vExecPath
vExecPath.Attach(vVar)
wcout <<L"ExecPath: "<<配模 (constwchar_t*)((_bstr_t)vExecPath) <<endl
}//else
}//信卖宴try
catch(_com_error &err)
{
cout <<"caught _com_error: "<<err.Error() <<endl
}//catch
进程ID就用L"ProcessID"获取
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)