当前位置: 首页>>代码示例>>C++>>正文


C++ ProcessId::write方法代码示例

本文整理汇总了C++中ProcessId::write方法的典型用法代码示例。如果您正苦于以下问题:C++ ProcessId::write方法的具体用法?C++ ProcessId::write怎么用?C++ ProcessId::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProcessId的用法示例。


在下文中一共展示了ProcessId::write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: util_create_lock_file

int util_create_lock_file(const char *lockFileName, bool abortDuplicates) {
	int result = 0;

	FILE *fp = safe_fopen_wrapper_follow( lockFileName, "w" );
	if ( fp == NULL ) {
		debug_printf( DEBUG_QUIET,
					"ERROR: could not open lock file %s for writing.\n",
					lockFileName);
		result = -1;
	}

		//
		// Create the ProcessId object.
		//
	ProcessId *procId = NULL;
	if ( result == 0 && abortDuplicates ) {
		int status;
		int precision_range = 1;
		if ( ProcAPI::createProcessId( daemonCore->getpid(), procId,
					status, &precision_range ) != PROCAPI_SUCCESS ) {
			debug_printf( DEBUG_QUIET, "ERROR: ProcAPI::createProcessId() "
						"failed; %d\n", status );
			result = -1;
		}
	}

		//
		// Write out the ProcessId object.
		//
	if ( result == 0 && abortDuplicates ) {
		if ( procId->write( fp ) != ProcessId::SUCCESS ) {
			debug_printf( DEBUG_QUIET, "ERROR: ProcessId::write() failed\n");
			result = -1;
		}
	}

		//
		// Sleep to ensure uniqueness of the ProcessId object.
		//
	if ( result == 0 && abortDuplicates ) {
		const int maxSleepTime = 60; // seconds; arbitrarily chosen
		int sleepTime = procId->computeWaitTime();

		if ( sleepTime > maxSleepTime ) {
			debug_printf( DEBUG_QUIET, "Warning: ProcessId computed sleep "
						"time (%d) exceeds maximum (%d); skipping sleep/"
						"confirm step\n", sleepTime, maxSleepTime );
			check_warning_strictness( DAG_STRICT_3 );
		} else {
			debug_printf( DEBUG_NORMAL, "Sleeping for %d seconds to "
						"ensure ProcessId uniqueness\n", sleepTime );

#if defined(WIN32)
			sleep( sleepTime );
#else
			while( (sleepTime = sleep( sleepTime ) ) != 0 ) { }
#endif

				//
				// Confirm the ProcessId object's uniqueness.
				//
			int status;
			if ( ProcAPI::confirmProcessId( *procId, status ) !=
						PROCAPI_SUCCESS ) {
				debug_printf( DEBUG_QUIET, "Warning: ProcAPI::"
							"confirmProcessId() failed; %d\n", status );
				check_warning_strictness( DAG_STRICT_3 );
			} else {
				if ( !procId->isConfirmed() ) {
					debug_printf( DEBUG_QUIET, "Warning: ProcessId not "
								"confirmed unique\n" );
					check_warning_strictness( DAG_STRICT_3 );
				} else {

						//
						// Write out the confirmation.
						//
					if ( procId->writeConfirmationOnly( fp ) !=
								ProcessId::SUCCESS ) {
						debug_printf( DEBUG_QUIET, "ERROR: ProcessId::"
									"writeConfirmationOnly() failed\n");
						result = -1;
					}
				}
			}
		}
	}

	delete procId;

	if ( fp != NULL ) {
		if ( fclose( fp ) != 0 ) {
			debug_printf( DEBUG_QUIET, "ERROR: closing lock "
						"file failed with errno %d (%s)\n", errno,
						strerror( errno ) );
		}
	}

	return result;
}
开发者ID:bbockelm,项目名称:htcondor,代码行数:100,代码来源:dagman_util.cpp


注:本文中的ProcessId::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。