本文整理汇总了C++中ProcessId::asUInt32方法的典型用法代码示例。如果您正苦于以下问题:C++ ProcessId::asUInt32方法的具体用法?C++ ProcessId::asUInt32怎么用?C++ ProcessId::asUInt32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProcessId
的用法示例。
在下文中一共展示了ProcessId::asUInt32方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LinuxProc
LinuxProc( ProcessId pid ) {
char name[128];
sprintf( name , "/proc/%d/stat" , pid.asUInt32() );
FILE * f = fopen( name , "r");
if ( ! f ) {
stringstream ss;
ss << "couldn't open [" << name << "] " << errnoWithDescription();
string s = ss.str();
// help the assert# control uasserted( 13538 , s.c_str() );
msgassertedNoTrace( 13538 , s.c_str() );
}
int found = fscanf(f,
"%d %127s %c "
"%d %d %d %d %d "
"%lu %lu %lu %lu %lu "
"%lu %lu %ld %ld " /* utime stime cutime cstime */
"%ld %ld "
"%ld "
"%ld "
"%lu " /* start_time */
"%lu "
"%ld " // rss
"%lu %" KLF "u %" KLF "u %" KLF "u %" KLF "u %" KLF "u "
/*
"%*s %*s %*s %*s "
"%"KLF"u %*lu %*lu "
"%d %d "
"%lu %lu"
*/
,
&_pid,
_comm,
&_state,
&_ppid, &_pgrp, &_session, &_tty, &_tpgid,
&_flags, &_min_flt, &_cmin_flt, &_maj_flt, &_cmaj_flt,
&_utime, &_stime, &_cutime, &_cstime,
&_priority, &_nice,
&_nlwp,
&_alarm,
&_start_time,
&_vsize,
&_rss,
&_rss_rlim, &_start_code, &_end_code, &_start_stack, &_kstk_esp, &_kstk_eip
/*
&_wchan,
&_exit_signal, &_processor,
&_rtprio, &_sched
*/
);
if ( found == 0 ) {
cout << "system error: reading proc info" << endl;
}
fclose( f );
}
示例2: kill_wrapper
inline void kill_wrapper( ProcessId pid, int sig, int port, const BSONObj& opt ) {
#ifdef _WIN32
if (sig == SIGKILL || port == 0) {
verify( registry._handles.count(pid) );
TerminateProcess(registry._handles[pid], 1); // returns failure for "zombie" processes.
return;
}
std::string eventName = getShutdownSignalName(pid.asUInt32());
HANDLE event = OpenEventA(EVENT_MODIFY_STATE, FALSE, eventName.c_str());
if (event == NULL) {
int gle = GetLastError();
if (gle != ERROR_FILE_NOT_FOUND) {
warning() << "kill_wrapper OpenEvent failed: " << errnoWithDescription();
}
else {
log() << "kill_wrapper OpenEvent failed to open event to the process "
<< pid.asUInt32() << ". It has likely died already";
}
return;
}
ON_BLOCK_EXIT(CloseHandle, event);
bool result = SetEvent(event);
if (!result) {
error() << "kill_wrapper SetEvent failed: " << errnoWithDescription();
return;
}
#else
int x = kill( pid.toNative(), sig );
if ( x ) {
if ( errno == ESRCH ) {
}
else {
log() << "killFailed: " << errnoWithDescription() << endl;
verify( x == 0 );
}
}
#endif
}
示例3: kill_wrapper
inline void kill_wrapper( ProcessId pid, int sig, int port, const BSONObj& opt ) {
#ifdef _WIN32
if (sig == SIGKILL || port == 0) {
verify( registry._handles.count(pid) );
TerminateProcess(registry._handles[pid], 1); // returns failure for "zombie" processes.
return;
}
std::string eventName = getShutdownSignalName(pid.asUInt32());
HANDLE event = OpenEventA(EVENT_MODIFY_STATE, FALSE, eventName.c_str());
if (event == NULL) {
int gle = GetLastError();
if (gle != ERROR_FILE_NOT_FOUND) {
warning() << "kill_wrapper OpenEvent failed: " << errnoWithDescription();
}
else {
log() << "kill_wrapper OpenEvent failed to open event to the process "
<< pid.asUInt32()
<< ". It has likely died already or server is running an older version."
<< " Attempting to shutdown through admin command.";
// Back-off to the old way of shutting down the server on Windows, in case we
// are managing a pre-2.6.0rc0 service, which did not have the event.
//
try {
DBClientConnection conn;
conn.connect("127.0.0.1:" + BSONObjBuilder::numStr(port));
BSONElement authObj = opt["auth"];
if (!authObj.eoo()){
string errMsg;
conn.auth("admin", authObj["user"].String(),
authObj["pwd"].String(), errMsg);
if (!errMsg.empty()) {
cout << "Failed to authenticate before shutdown: "
<< errMsg << endl;
}
}
BSONObj info;
BSONObjBuilder b;
b.append("shutdown", 1);
b.append("force", 1);
conn.runCommand("admin", b.done(), info);
}
catch (...) {
// Do nothing. This command never returns data to the client and the driver
// doesn't like that.
//
}
}
return;
}
ON_BLOCK_EXIT(CloseHandle, event);
bool result = SetEvent(event);
if (!result) {
error() << "kill_wrapper SetEvent failed: " << errnoWithDescription();
return;
}
#else
int x = kill( pid.toNative(), sig );
if ( x ) {
if ( errno == ESRCH ) {
}
else {
log() << "killFailed: " << errnoWithDescription() << endl;
verify( x == 0 );
}
}
#endif
}