本文整理汇总了C++中setpriority函数的典型用法代码示例。如果您正苦于以下问题:C++ setpriority函数的具体用法?C++ setpriority怎么用?C++ setpriority使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setpriority函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sprintf
void dockingportGSP::init()
{
/////////////////// Set process priorities
int prior;
int dummy1;
/// set process priority of ueye usb daemon to highest possible value
char reniceCmd[100];
string processIDofUeyeDeamonStr;
int processIDofUeyeDeamon;
char pidOfCmd[100];
sprintf(pidOfCmd, "pidof ueyeusbd");
processIDofUeyeDeamonStr = this->execAndReturnSystemOutput(pidOfCmd);
processIDofUeyeDeamon = atoi(processIDofUeyeDeamonStr.c_str());
sprintf(reniceCmd, "sudo renice -20 %d", processIDofUeyeDeamon);
dummy1 = system(reniceCmd);
prior = getpriority(PRIO_PROCESS, processIDofUeyeDeamon);
printf("\n ueyeusbd process priority set to: %d\n",prior);
/// set process priority of TestProject process to a value slightly lower than ueye usb daemon
setpriority(PRIO_PROCESS,0,-15);
usleep(10000);
prior = getpriority(PRIO_PROCESS,0);
printf(" TestProject process priority set to: %d\n",prior);
this->useBackgroundTask = false;
prevImageTimeStamp = 0;
/////////////////// Path Initializations
sprintf(this->calibParamDir, "/opt/GogglesOptics/Calib_Params/%s", this->calibParamSetName); //set the parameter directory to be what we enter in command line
///////////////////
/////////////////// Camera Initialization section
GSPretVal = camera.initOneCamera(); // Errors handled within functions
if (GSPretVal != 0)
{
printf("Camera could not be initialized!\n");
return exit(1);
}
// Start camera
GSPretVal = camera.startOneCamera(); // Errors handled within functions
if (GSPretVal != 0)
{
printf("Camera could not be started!\n");
return exit(1);
}
////////////////// UDP PIC INITIALIZATION
if (useUDP_PIC)
this->connectToPIC();
///////////////////
/////////////////// Image Rectification Initialization
GSPretVal = rectifier.calcRectificationMaps(camera.getImageWidth(), camera.getImageHeight(), this->calibParamDir);
if (GSPretVal != 0)
{
cout << "Rectification maps could not be processed!" << endl;
}
///////////////////
/////////////////// Data Storage Initialization
datastorage.initDataStorage(this->dockportName, this->camera_ID, this->runPath, this->camera.getImageWidth(), this->camera.getImageHeight());
if (datastorage.autoImageStorage)
{
// create image-datastorage thread
GSPretVal = pthread_create(&ImageStorageThread, NULL, this->imageStorage_thread_Helper, this);
if (GSPretVal != 0)
{
printf("pthread_create ImageStorageThread failed\n");
return exit(1);
}
}
///////////////////
/////////////////// Initialization of OpenCV Mats with correct Size (depending on the parameter/boolean camera.reduceImageSizeTo320x240)
singleImage.create(camera.getImageHeight(), camera.getImageWidth(), CV_8UC3);
///////////////////
}
示例2: main
//.........这里部分代码省略.........
// Initialize the signal handlers
AuthServerSignalHandler SignalINT, SignalTERM;
// Register authservers's signal handlers
ACE_Sig_Handler Handler;
Handler.register_handler(SIGINT, &SignalINT);
Handler.register_handler(SIGTERM, &SignalTERM);
///- Handle affinity for multiple processors and process priority
uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0);
bool highPriority = sConfigMgr->GetBoolDefault("ProcessPriority", false);
#ifdef _WIN32 // Windows
{
HANDLE hProcess = GetCurrentProcess();
if (affinity > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR currentAffinity = affinity & appAff; // remove non accessible processors
if (!currentAffinity)
TC_LOG_ERROR("server.authserver", "RageFire: Processors marked in UseProcessors bitmask (hex) %x are not accessible for the authserver. Accessible processors bitmask (hex): %x", affinity, appAff);
else if (SetProcessAffinityMask(hProcess, currentAffinity))
TC_LOG_INFO("server.authserver", "RageFire: Using processors (bitmask, hex): %x", currentAffinity);
else
TC_LOG_ERROR("server.authserver", "RageFire: Can't set used processors (hex): %x", currentAffinity);
}
}
if (highPriority)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
TC_LOG_INFO("server.authserver", "RageFire: authserver process priority class set to HIGH");
else
TC_LOG_ERROR("server.authserver", "RageFire: Can't set authserver process priority class.");
}
}
#elif __linux__ // Linux
if (affinity > 0)
{
cpu_set_t mask;
CPU_ZERO(&mask);
for (unsigned int i = 0; i < sizeof(affinity) * 8; ++i)
if (affinity & (1 << i))
CPU_SET(i, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
TC_LOG_ERROR("server.authserver", "RageFire: Can't set used processors (hex): %x, error: %s", affinity, strerror(errno));
else
{
CPU_ZERO(&mask);
sched_getaffinity(0, sizeof(mask), &mask);
TC_LOG_INFO("server.authserver", "RageFire: Using processors (bitmask, hex): %lx", *(__cpu_mask*)(&mask));
}
}
if (highPriority)
{
if (setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
TC_LOG_ERROR("server.authserver", "RageFire: Can't set authserver process priority class, error: %s", strerror(errno));
else
TC_LOG_INFO("server.authserver", "RageFire: authserver process priority class set to %i", getpriority(PRIO_PROCESS, 0));
}
#endif
// maximum counter for next ping
uint32 numLoops = (sConfigMgr->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
uint32 loopCounter = 0;
// Wait for termination signal
while (!stopEvent)
{
// dont move this outside the loop, the reactor will modify it
ACE_Time_Value interval(0, 100000);
if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
break;
if ((++loopCounter) == numLoops)
{
loopCounter = 0;
TC_LOG_INFO("server.authserver", "RageFire: Ping MySQL to keep connection alive");
LoginDatabase.KeepAlive();
}
}
// Close the Database Pool and library
StopDB();
TC_LOG_INFO("server.authserver", "RageFire: Halting process...");
return 0;
}
示例3: main
int main(int argc, char **argv)
{
/* For select(2). */
struct timeval tv;
fd_set in;
/* For parsing arguments. */
char *cp;
/* The key read in. */
char c;
get_options();
/*
* Parse arguments.
*/
argv++;
while (*argv) {
cp = *argv++;
while (*cp) {
switch (*cp) {
case 'd':
if (cp[1]) {
if (sscanf(++cp, "%f", &Sleeptime) != 1) {
fprintf(stderr, PROGNAME ": Bad delay time `%s'\n", cp);
exit(1);
}
goto breakargv;
} else if (*argv) { /* last char in an argv, use next as arg */
if (sscanf(cp = *argv++, "%f", &Sleeptime) != 1) {
fprintf(stderr, PROGNAME ": Bad delay time `%s'\n", cp);
exit(1);
}
goto breakargv;
} else {
fprintf(stderr, "-d requires an argument\n");
exit(1);
}
break;
case 'q':
if (!getuid())
/* set priority to -10 in order to stay above kswapd */
if (setpriority(PRIO_PROCESS, getpid(), -10)) {
/* We check this just for paranoia. It's not
fatal, and shouldn't happen. */
perror(PROGNAME ": setpriority() failed");
}
Sleeptime = 0;
break;
case 'c':
show_cmd = !show_cmd;
break;
case 'S':
Cumulative = 1;
break;
case 'i':
Noidle = 1;
break;
case 's':
Secure = 1;
break;
case '-':
break; /* Just ignore it */
#if defined (SHOWFLAG)
case '/': showall++;
#endif
default:
fprintf(stderr, PROGNAME ": Unknown argument `%c'\n", *cp);
exit(1);
}
cp++;
}
breakargv:
}
/* set to PCPU sorting */
register_sort_function( -1, (cmp_t)pcpu_sort);
/* for correct handling of some fields, we have to do distinguish
* between kernel versions */
set_linux_version();
/* get kernel symbol table, if needed */
if (!CL_wchan_nout) {
if (open_psdb()) {
CL_wchan_nout = 1;
} else {
psdbsucc = 1;
}
}
setup_terminal();
window_size();
/*
* calculate header size, length of cmdline field ...
*/
Numfields = make_header();
/*
* Set up signal handlers.
*/
signal(SIGHUP, (void *) (int) end);
signal(SIGINT, (void *) (int) end);
signal(SIGQUIT, (void *) (int) end);
//.........这里部分代码省略.........
示例4: client
static void
client (int fd, const char* prio, unsigned int text_size, struct test_st *test)
{
int ret;
char buffer[MAX_BUF + 1];
char text[text_size];
gnutls_certificate_credentials_t x509_cred;
gnutls_session_t session;
struct timespec start, stop;
static unsigned long taken = 0;
static unsigned long measurement;
const char* err;
global_init ();
setpriority(PRIO_PROCESS, getpid(), -15);
memset(text, 0, text_size);
#ifdef DEBUG
gnutls_global_set_log_function (client_log_func);
gnutls_global_set_log_level (6);
#endif
gnutls_certificate_allocate_credentials (&x509_cred);
#ifdef REHANDSHAKE
restart:
#endif
/* Initialize TLS session
*/
gnutls_init (&session, GNUTLS_CLIENT);
gnutls_session_set_ptr(session, test);
cli_session = session;
/* Use default priorities */
if ((ret=gnutls_priority_set_direct (session, prio, &err)) < 0) {
fprintf(stderr, "Error in priority string %s: %s\n", gnutls_strerror(ret), err);
exit(1);
}
/* put the anonymous credentials to the current session
*/
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, x509_cred);
gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) fd);
/* Perform the TLS handshake
*/
do
{
ret = gnutls_handshake (session);
}
while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
if (ret < 0)
{
fprintf (stderr, "client: Handshake failed\n");
gnutls_perror (ret);
exit(1);
}
ret = gnutls_protocol_get_version(session);
if (ret < GNUTLS_TLS1_1)
{
fprintf (stderr, "client: Handshake didn't negotiate TLS 1.1 (or later)\n");
exit(1);
}
gnutls_transport_set_push_function (session, push_crippled);
#ifndef REHANDSHAKE
restart:
#endif
do {
ret = gnutls_record_send (session, text, sizeof(text));
} while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
/* measure peer's processing time */
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
#define TLS_RECV
#ifdef TLS_RECV
do {
ret = gnutls_record_recv(session, buffer, sizeof(buffer));
} while(ret < 0 && (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED));
#else
do {
ret = recv(fd, buffer, sizeof(buffer), 0);
} while(ret == -1 && errno == EAGAIN);
#endif
if (taken < MAX_MEASUREMENTS(test->npoints) && ret > 0)
{
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop);
taken++;
measurement = timespec_sub_ns(&stop, &start);
prev_point_ptr->measurements[prev_point_ptr->midx] = measurement;
/*fprintf(stderr, "(%u,%u): %lu\n", (unsigned) prev_point_ptr->byte1,
(unsigned) prev_point_ptr->byte2, measurements[taken]);*/
//.........这里部分代码省略.........
示例5: ngx_worker_process_init
// worker进程,cachemanager进程和cacheloader进程的初始化函数
static void
ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
{
sigset_t set;
uint64_t cpu_affinity;
ngx_int_t n;
ngx_uint_t i;
struct rlimit rlmt;
ngx_core_conf_t *ccf;
ngx_listening_t *ls;
if (ngx_set_environment(cycle, NULL) == NULL) {
/* fatal */
exit(2);
}
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
// 设置worker进程的nice值,cachemanager cacheloader进程不会设置
if (worker >= 0 && ccf->priority != 0) {
if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setpriority(%d) failed", ccf->priority);
}
}
// 设置进程最多可以打开的fd数量
if (ccf->rlimit_nofile != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;
if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_NOFILE, %i) failed",
ccf->rlimit_nofile);
}
}
// 设置这个进程独立于系统的coredump属性
if (ccf->rlimit_core != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_core;
rlmt.rlim_max = (rlim_t) ccf->rlimit_core;
if (setrlimit(RLIMIT_CORE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_CORE, %O) failed",
ccf->rlimit_core);
}
}
#ifdef RLIMIT_SIGPENDING
if (ccf->rlimit_sigpending != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending;
rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending;
if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_SIGPENDING, %i) failed",
ccf->rlimit_sigpending);
}
}
#endif
// 如果设置了user指令,而且使用root权限启动会在这里改变进程所属的用户和组
if (geteuid() == 0) {
if (setgid(ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setgid(%d) failed", ccf->group);
/* fatal */
exit(2);
}
if (initgroups(ccf->username, ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"initgroups(%s, %d) failed",
ccf->username, ccf->group);
}
if (setuid(ccf->user) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setuid(%d) failed", ccf->user);
/* fatal */
exit(2);
}
}
if (worker >= 0) {
// 获取这个worker对应的CPU号
cpu_affinity = ngx_get_cpu_affinity(worker);
// 绑定这个worker对应的CPU。
if (cpu_affinity) {
ngx_setaffinity(cpu_affinity, cycle->log);
}
}
#if (NGX_HAVE_PR_SET_DUMPABLE)
//.........这里部分代码省略.........
示例6: ngx_worker_process_init
static void
ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
{
sigset_t set;
ngx_int_t n;
ngx_uint_t i;
struct rlimit rlmt;
ngx_core_conf_t *ccf;
ngx_listening_t *ls;
if (ngx_set_environment(cycle, NULL) == NULL) {
/* fatal */
exit(2);
}
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (priority && ccf->priority != 0) {
if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setpriority(%d) failed", ccf->priority);
}
}
if (ccf->rlimit_nofile != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;
if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_NOFILE, %i) failed",
ccf->rlimit_nofile);
}
}
if (ccf->rlimit_core != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_core;
rlmt.rlim_max = (rlim_t) ccf->rlimit_core;
if (setrlimit(RLIMIT_CORE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_CORE, %O) failed",
ccf->rlimit_core);
}
}
#ifdef RLIMIT_SIGPENDING
if (ccf->rlimit_sigpending != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending;
rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending;
if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_SIGPENDING, %i) failed",
ccf->rlimit_sigpending);
}
}
#endif
if (geteuid() == 0) {
if (setgid(ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setgid(%d) failed", ccf->group);
/* fatal */
exit(2);
}
if (initgroups(ccf->username, ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"initgroups(%s, %d) failed",
ccf->username, ccf->group);
}
if (setuid(ccf->user) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setuid(%d) failed", ccf->user);
/* fatal */
exit(2);
}
}
#if (NGX_HAVE_SCHED_SETAFFINITY)
if (cpu_affinity) {
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
"sched_setaffinity(0x%08Xl)", cpu_affinity);
if (sched_setaffinity(0, 32, (cpu_set_t *) &cpu_affinity) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"sched_setaffinity(0x%08Xl) failed", cpu_affinity);
}
}
#endif
#if (NGX_HAVE_PR_SET_DUMPABLE)
/* allow coredump after setuid() in Linux 2.4.x */
if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
//.........这里部分代码省略.........
示例7: SetPriority
void cThread::SetPriority(int Priority)
{
if (setpriority(PRIO_PROCESS, 0, Priority) < 0)
LOG_ERROR;
}
示例8: action_launch_child
static void
action_launch_child(svc_action_t *op)
{
int lpc;
/* SIGPIPE is ignored (which is different from signal blocking) by the gnutls library.
* Depending on the libqb version in use, libqb may set SIGPIPE to be ignored as well.
* We do not want this to be inherited by the child process. By resetting this the signal
* to the default behavior, we avoid some potential odd problems that occur during OCF
* scripts when SIGPIPE is ignored by the environment. */
signal(SIGPIPE, SIG_DFL);
#if defined(HAVE_SCHED_SETSCHEDULER)
if (sched_getscheduler(0) != SCHED_OTHER) {
struct sched_param sp;
memset(&sp, 0, sizeof(sp));
sp.sched_priority = 0;
if (sched_setscheduler(0, SCHED_OTHER, &sp) == -1) {
crm_perror(LOG_ERR, "Could not reset scheduling policy to SCHED_OTHER for %s", op->id);
}
}
#endif
if (setpriority(PRIO_PROCESS, 0, 0) == -1) {
crm_perror(LOG_ERR, "Could not reset process priority to 0 for %s", op->id);
}
/* Man: The call setpgrp() is equivalent to setpgid(0,0)
* _and_ compiles on BSD variants too
* need to investigate if it works the same too.
*/
setpgid(0, 0);
/* close all descriptors except stdin/out/err and channels to logd */
for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
close(lpc);
}
#if SUPPORT_CIBSECRETS
if (replace_secret_params(op->rsc, op->params) < 0) {
/* replacing secrets failed! */
if (safe_str_eq(op->action,"stop")) {
/* don't fail on stop! */
crm_info("proceeding with the stop operation for %s", op->rsc);
} else {
crm_err("failed to get secrets for %s, "
"considering resource not configured", op->rsc);
_exit(PCMK_OCF_NOT_CONFIGURED);
}
}
#endif
/* Setup environment correctly */
add_OCF_env_vars(op);
/* execute the RA */
execvp(op->opaque->exec, op->opaque->args);
/* Most cases should have been already handled by stat() */
services_handle_exec_error(op, errno);
_exit(op->rc);
}
示例9: main
//.........这里部分代码省略.........
}
}
/* Start logging to syslog and stderr */
openlog("hciemu", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON);
syslog(LOG_INFO, "HCI emulation daemon ver %s started", VERSION);
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_NOCLDSTOP;
sa.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
sa.sa_handler = sig_term;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
if (!device)
device = strdup(VHCI_DEV);
/* Open and create virtual HCI device */
device_fd = open(device, O_RDWR);
if (device_fd < 0) {
syslog(LOG_ERR, "Can't open device %s: %s (%d)",
device, strerror(errno), errno);
free(device);
return exitcode;
}
free(device);
/* Create snoop file */
if (snoop) {
dd = create_snoop(snoop);
if (dd < 0)
syslog(LOG_ERR, "Can't create snoop file %s: %s (%d)",
snoop, strerror(errno), errno);
free(snoop);
} else
dd = -1;
/* Create event loop */
epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (epoll_fd < 0) {
perror("Failed to create epoll descriptor");
goto close_device;
}
reset_vdev();
vdev.dev_fd = device_fd;
vdev.dd = dd;
memset(&device_event, 0, sizeof(device_event));
device_event.events = EPOLLIN;
device_event.data.fd = device_fd;
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, device_fd, &device_event) < 0) {
perror("Failed to setup device event watch");
goto close_device;
}
setpriority(PRIO_PROCESS, 0, -19);
/* Start event processor */
for (;;) {
struct epoll_event events[MAX_EPOLL_EVENTS];
int n, nfds;
if (__io_canceled)
break;
nfds = epoll_wait(epoll_fd, events, MAX_EPOLL_EVENTS, -1);
if (nfds < 0)
continue;
for (n = 0; n < nfds; n++) {
if (events[n].data.fd == vdev.dev_fd)
io_hci_data();
else if (events[n].data.fd == vdev.scan_fd)
io_conn_ind();
}
}
exitcode = EXIT_SUCCESS;
epoll_ctl(epoll_fd, EPOLL_CTL_DEL, device_fd, NULL);
close_device:
close(device_fd);
if (dd >= 0)
close(dd);
close(epoll_fd);
syslog(LOG_INFO, "Exit");
return exitcode;
}
示例10: main
int main(int argc, char **argv) {
//
// Machine d'état
//
// int state
// -1: erreur
// 0: non initialisé
// 1: initialisé, pret rotation
// 2: rotation, pret décollage
// 3: décollage
// 4: vol normal
// 5: atterissage
//
state = 0;
printf("\n");
printf("\n================================================");
printf("\n===== XMicroDrone - Controlleur V1.1 =====");
printf("\n================================================");
printf("\n");
//
// Récupérons les numéros de devices séries (paramétre optionnel)
//
int premierDevice = 0; // La valeur par défaut, qu'on utilisera s'il n'y a pas d'arguments
if (argc >= 2) {
int arg = atoi(argv[1]);
if (arg >= 0 && arg <= 2) {
premierDevice = arg;
} else {
printf("Argument devices hors de portée.\n");
}
}
//---------------------------------------------------------------------------
//
//
// INITIALISATION DU PROGRAMME
//
//
//---------------------------------------------------------------------------
//
// Rend le fgets sur stdin non bloquant; FONCTIONNE !
//
int flags = fcntl(0, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(0, F_SETFL, flags);
printf("Initialisation des différents modules...");
fflush(stdout);
Misc_Initialise(); // Ne dépend de rien d'autre // Pas de blabla
Maths_Initialise(); // Ne dépend de rien d'autre // Pas de blabla
Params_Initialise(); // Après Maths_Initialise(); (peut utiliser des maths) // Pas de blabla
Asservissement_Initialise(); // Après Params_Initialise();
//Pilote_Initialise(); // Après Params, // Pas de blabla
printf(" OK\n");
printf("Fermeture des serveurs port séries...");
fflush(stdout);
//system("pkill -9 xuartctl"); // kill tous les process utilisant xuartctl TS7500
//usleep(100 * 1000);
printf(" OK... - A priori, A voir si on en a besoin - Pour l'instant ne fait rien\n");
// La fonction suivante émet son propre blabla
I2C_Initialise();
Controlleur_Initialise(0); // Aprés Params_Initialise() et I2C_initialise; // Argument: 1 pour allumer les moteurs successivement
//int grnLedOn = 0;
//int redLedOn = 0;
//Misc_SetRedLed(0); //TS7500
//Misc_SetGrnLed(0);
if (0) {
CommWiFi_Initialise(); // Emet son propre blabla
}
// On se donne temporairement la priorité -15 pour que les xuart l'aient
//
// -15 pour les xuartctl (Port séries) et ts7500ctl (I2C)
// -10 pour nous et ts7500ctl
// -5 pour les trucs systemes importants
// 0 pour le reste
// Plage: -20 (haute priorité) é +20 (faible priorité)
int usePrio = 0;
if (usePrio && setpriority(PRIO_PROCESS, getpid(), -15)) {
printf("ERREUR: setpriority\n");
}
Centrale_Initialise(premierDevice); // Argument: le dev par défaut, -1 pour laisser l'utilisateur choisir
Sonar_Initialise(premierDevice + 1); // Argument: le dev par défaut, -1 pour laisser l'utilisateur choisir
// On se replace a -10
if (usePrio && setpriority(PRIO_PROCESS, getpid(), -10)) {
//.........这里部分代码省略.........
示例11: main
int main(int argc, char *argv[])
{
int ret = ERROR_OK;
int err_count = 0;
int rcv_err_count = 0;
bool msg_received = false;
char* device;
/* Para parsear el los mensajes se recorre el arreglo con un puntero
* a enteros de dos bytes.
*/
int16_t *ch_buff;
//char str[128]; // dbg
// check input arguments
if(argc<2)
{
err_log(HOW_TO);
return -1;
}
else device = argv[1];
struct timeval tv_in;
struct timeval tv_end;
struct timeval tv_diff;
#if DEBUG_TIMING_SBUSD
struct timeval tv_last;
#endif //#if DEBUG_TIMING_SBUSD
#if !PC_TEST
fd = open_port(device);
if (fd == -1)
{
return -1;
}
configure_port(fd);
ret = custom_baud(fd);
if (ret < 0)
{
err_log_stderr("custom_baud() failed!");
return ret;
}
#endif
/**
* Inherit priority from main.c for correct IPC.
*/
if(setpriority(PRIO_PROCESS, 0, -18) == -1) //requires being superuser
{
err_log_num("setpriority() failed!",errno);
return -1;
}
// Catch signals
prctl(PR_SET_PDEATHSIG, SIGHUP);
signal(SIGHUP, uquad_sig_handler);
signal(SIGINT, uquad_sig_handler);
signal(SIGQUIT, uquad_sig_handler);
#if PC_TEST
futaba_sbus_begin(); //para tiempo de start
#endif //PC_TEST
// Lleva a cero todos los canales y el mensaje sbus
futaba_sbus_set_channel(ROLL_CHANNEL, 1500); //init roll en cero
futaba_sbus_set_channel(PITCH_CHANNEL, 1500); //init pitch en cero
futaba_sbus_set_channel(YAW_CHANNEL, 1500); //init yaw en cero
futaba_sbus_set_channel(THROTTLE_CHANNEL, 950); //init throttle en minimo
futaba_sbus_set_channel(FLIGHTMODE_CHANNEL, 1500); //inint flight mode 2
futaba_sbus_update_msg();
sleep_ms(500); //Para ponerme a tiro con main
bool main_ready = false;
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// Loop
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(;;)
{
gettimeofday(&tv_in,NULL);
//printf("errores: %d\n",err_count);//dbg
#if !PC_TEST
if (err_count > MAX_ERR_SBUSD)
{
err_log("error count exceded");
//err_count = 0;
quit();
}
#endif
ret = uquad_read(&rbuf);
if(ret == ERROR_OK)
{
if(!main_ready) main_ready = true;
//err_log("read ok!");
msg_received = true;
//.........这里部分代码省略.........
示例12: main
int main(int argc, char **argv)
{
int c;
int cnt;
char *childArgv[10];
char *buff;
int childArgc = 0;
int retcode;
char *pwdbuf = NULL;
struct passwd *pwd = NULL, _pwd;
struct login_context cxt = {
.tty_mode = TTY_MODE, /* tty chmod() */
.pid = getpid(), /* PID */
.conv = { misc_conv, NULL } /* PAM conversation function */
};
timeout = (unsigned int)getlogindefs_num("LOGIN_TIMEOUT", LOGIN_TIMEOUT);
signal(SIGALRM, timedout);
siginterrupt(SIGALRM, 1); /* we have to interrupt syscalls like ioclt() */
alarm(timeout);
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, SIG_IGN);
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
setpriority(PRIO_PROCESS, 0, 0);
initproctitle(argc, argv);
/*
* -p is used by getty to tell login not to destroy the environment
* -f is used to skip a second login authentication
* -h is used by other servers to pass the name of the remote
* host to login so that it may be placed in utmp and wtmp
*/
while ((c = getopt(argc, argv, "fHh:pV")) != -1)
switch (c) {
case 'f':
cxt.noauth = 1;
break;
case 'H':
cxt.nohost = 1;
break;
case 'h':
if (getuid()) {
fprintf(stderr,
_("login: -h for super-user only.\n"));
exit(EXIT_FAILURE);
}
init_remote_info(&cxt, optarg);
break;
case 'p':
cxt.keep_env = 1;
break;
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case '?':
default:
fprintf(stderr, _("usage: login [ -p ] [ -h host ] [ -H ] [ -f username | username ]\n"));
exit(EXIT_FAILURE);
}
argc -= optind;
argv += optind;
if (*argv) {
char *p = *argv;
cxt.username = xstrdup(p);
/* wipe name - some people mistype their password here */
/* (of course we are too late, but perhaps this helps a little ..) */
while (*p)
*p++ = ' ';
}
for (cnt = get_fd_tabsize() - 1; cnt > 2; cnt--)
close(cnt);
setpgrp(); /* set pgid to pid this means that setsid() will fail */
openlog("login", LOG_ODELAY, LOG_AUTHPRIV);
init_tty(&cxt);
init_loginpam(&cxt);
/* login -f, then the user has already been authenticated */
cxt.noauth = cxt.noauth && getuid() == 0 ? 1 : 0;
if (!cxt.noauth)
loginpam_auth(&cxt);
/*
//.........这里部分代码省略.........
示例13: prctl
void *SpeechVMRecorder::DumpVMRecordDataThread(void *arg)
{
// Adjust thread priority
prctl(PR_SET_NAME, (unsigned long)__FUNCTION__, 0, 0, 0);
setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
ALOGD("%s(), pid: %d, tid: %d", __FUNCTION__, getpid(), gettid());
SpeechVMRecorder *pSpeechVMRecorder = (SpeechVMRecorder *)arg;
RingBuf &ring_buf = pSpeechVMRecorder->mRingBuf;
// open file
if (pSpeechVMRecorder->OpenFile() != NO_ERROR)
{
pSpeechVMRecorder->mEnable = false;
pthread_exit(NULL);
return 0;
}
// open modem record function
SpeechDriverInterface *pSpeechDriver = SpeechDriverFactory::GetInstance()->GetSpeechDriver();
status_t retval = pSpeechDriver->VoiceMemoRecordOn();
if (retval != NO_ERROR)
{
ALOGE("%s(), VoiceMemoRecordOn() fail!! Return.", __FUNCTION__);
pSpeechDriver->VoiceMemoRecordOff();
pSpeechVMRecorder->mEnable = false;
pthread_exit(NULL);
return 0;
}
// Internal Input Buffer Initialization
pSpeechVMRecorder->mRingBuf.pBufBase = new char[kReadBufferSize];
pSpeechVMRecorder->mRingBuf.bufLen = kReadBufferSize;
pSpeechVMRecorder->mRingBuf.pRead = pSpeechVMRecorder->mRingBuf.pBufBase;
pSpeechVMRecorder->mRingBuf.pWrite = pSpeechVMRecorder->mRingBuf.pBufBase;
ASSERT(pSpeechVMRecorder->mRingBuf.pBufBase != NULL);
memset(pSpeechVMRecorder->mRingBuf.pBufBase, 0, pSpeechVMRecorder->mRingBuf.bufLen);
pSpeechVMRecorder->mStarting = true;
while (1)
{
// lock & wait data
pthread_mutex_lock(&pSpeechVMRecorder->mMutex);
int ret = pthread_cond_timeout_np(&pSpeechVMRecorder->mExitCond, &pSpeechVMRecorder->mMutex, kCondWaitTimeoutMsec);
if (ret != 0)
{
ALOGW("%s(), pthread_cond_timeout_np return %d. ", __FUNCTION__, ret);
}
// make sure VM is still recording after conditional wait
if (pSpeechVMRecorder->mEnable == false)
{
// close file
if (pSpeechVMRecorder->mDumpFile != NULL)
{
fflush(pSpeechVMRecorder->mDumpFile);
fclose(pSpeechVMRecorder->mDumpFile);
pSpeechVMRecorder->mDumpFile = NULL;
}
// release local ring buffer
if (pSpeechVMRecorder->mRingBuf.pBufBase != NULL)
{
delete []pSpeechVMRecorder->mRingBuf.pBufBase;
pSpeechVMRecorder->mRingBuf.pBufBase = NULL;
pSpeechVMRecorder->mRingBuf.pRead = NULL;
pSpeechVMRecorder->mRingBuf.pWrite = NULL;
pSpeechVMRecorder->mRingBuf.bufLen = 0;
}
ALOGD("%s(), pid: %d, tid: %d, mEnable == false, break.", __FUNCTION__, getpid(), gettid());
pthread_mutex_unlock(&pSpeechVMRecorder->mMutex);
break;
}
// write data to sd card
const uint16_t data_count = RingBuf_getDataCount(&ring_buf);
uint16_t write_bytes = 0;
if (data_count > 0)
{
const char *end = ring_buf.pBufBase + ring_buf.bufLen;
if (ring_buf.pRead <= ring_buf.pWrite)
{
write_bytes += fwrite((void *)ring_buf.pRead, sizeof(char), data_count, pSpeechVMRecorder->mDumpFile);
}
else
{
int r2e = end - ring_buf.pRead;
write_bytes += fwrite((void *)ring_buf.pRead, sizeof(char), r2e, pSpeechVMRecorder->mDumpFile);
write_bytes += fwrite((void *)ring_buf.pBufBase, sizeof(char), data_count - r2e, pSpeechVMRecorder->mDumpFile);
}
ring_buf.pRead += write_bytes;
if (ring_buf.pRead >= end) { ring_buf.pRead -= ring_buf.bufLen; }
//.........这里部分代码省略.........
示例14: vegas_rawdisk_thread
void vegas_rawdisk_thread(void *_args) {
/* Set cpu affinity */
cpu_set_t cpuset, cpuset_orig;
sched_getaffinity(0, sizeof(cpu_set_t), &cpuset_orig);
CPU_ZERO(&cpuset);
CPU_SET(1, &cpuset);
int rv = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
if (rv<0) {
vegas_error("vegas_rawdisk_thread", "Error setting cpu affinity.");
perror("sched_setaffinity");
}
/* Get args */
struct vegas_thread_args *args = (struct vegas_thread_args *)_args;
/* get instance_id */
int instance_id = args->instance_id;
/* Set priority */
rv = setpriority(PRIO_PROCESS, 0, 0);
if (rv<0) {
vegas_error("vegas_rawdisk_thread", "Error setting priority level.");
perror("set_priority");
}
/* Attach to status shared mem area */
struct vegas_status st;
rv = vegas_status_attach(instance_id, &st);
if (rv!=VEGAS_OK) {
vegas_error("vegas_rawdisk_thread",
"Error attaching to status shared memory.");
pthread_exit(NULL);
}
pthread_cleanup_push((void *)vegas_status_detach, &st);
pthread_cleanup_push((void *)set_exit_status, &st);
/* Init status */
vegas_status_lock_safe(&st);
hputs(st.buf, STATUS_KEY, "init");
vegas_status_unlock_safe(&st);
/* Read in general parameters */
struct vegas_params gp;
struct sdfits sf;
pthread_cleanup_push((void *)vegas_free_sdfits, &sf);
/* Attach to databuf shared mem */
struct vegas_databuf *db;
db = vegas_databuf_attach(instance_id, args->input_buffer);
if (db==NULL) {
vegas_error("vegas_rawdisk_thread",
"Error attaching to databuf shared memory.");
pthread_exit(NULL);
}
pthread_cleanup_push((void *)vegas_databuf_detach, db);
/* Init output file */
FILE *fraw = NULL;
pthread_cleanup_push((void *)safe_fclose, fraw);
/* Loop */
int blocksize=0;
int curblock=0, dataset;
int block_count=0, blocks_per_file=128, filenum=0;
int first=1;
char *ptr;
float *data_array;
struct databuf_index* db_index;
signal(SIGINT,cc);
while (run) {
/* Note waiting status */
vegas_status_lock_safe(&st);
hputs(st.buf, STATUS_KEY, "waiting");
vegas_status_unlock_safe(&st);
/* Wait for buf to have data */
rv = vegas_databuf_wait_filled(db, curblock);
if (rv!=0) continue;
/* Read param struct and index for this block */
ptr = vegas_databuf_header(db, curblock);
db_index = (struct databuf_index*)(vegas_databuf_index(db, curblock));
/* If first time running */
if (first==1)
{
first = 0;
vegas_read_obs_params(ptr, &gp, &sf);
char fname[256];
sprintf(fname, "%s_%4d.raw", sf.basefilename, filenum);
fprintf(stderr, "Opening raw file '%s'\n", fname);
// TODO: check for file exist.
fraw = fopen(fname, "wb");
if (fraw==NULL) {
vegas_error("vegas_rawdisk_thread", "Error opening file.");
//.........这里部分代码省略.........
示例15: ngx_worker_process_init
/* 工作进程初始化,
* worker表示创建的是第几个进程
*/
static void
ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
{
sigset_t set;
uint64_t cpu_affinity;
ngx_int_t n;
ngx_uint_t i;
struct rlimit rlmt;
ngx_core_conf_t *ccf;
ngx_listening_t *ls;
if (ngx_set_environment(cycle, NULL) == NULL) {
/* fatal */
exit(2);
}
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (worker >= 0 && ccf->priority != 0) {
/* 设置进程的优先级 */
if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setpriority(%d) failed", ccf->priority);
}
}
if (ccf->rlimit_nofile != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;
if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_NOFILE, %i) failed",
ccf->rlimit_nofile);
}
}
if (ccf->rlimit_core != NGX_CONF_UNSET) {
rlmt.rlim_cur = (rlim_t) ccf->rlimit_core;
rlmt.rlim_max = (rlim_t) ccf->rlimit_core;
if (setrlimit(RLIMIT_CORE, &rlmt) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setrlimit(RLIMIT_CORE, %O) failed",
ccf->rlimit_core);
}
}
if (geteuid() == 0) {
if (setgid(ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setgid(%d) failed", ccf->group);
/* fatal */
exit(2);
}
if (initgroups(ccf->username, ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"initgroups(%s, %d) failed",
ccf->username, ccf->group);
}
if (setuid(ccf->user) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setuid(%d) failed", ccf->user);
/* fatal */
exit(2);
}
}
if (worker >= 0) {
cpu_affinity = ngx_get_cpu_affinity(worker);
if (cpu_affinity) {
ngx_setaffinity(cpu_affinity, cycle->log);
}
}
#if (NGX_HAVE_PR_SET_DUMPABLE)
/* allow coredump after setuid() in Linux 2.4.x */
if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"prctl(PR_SET_DUMPABLE) failed");
}
#endif
if (ccf->working_directory.len) {
if (chdir((char *) ccf->working_directory.data) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"chdir(\"%s\") failed", ccf->working_directory.data);
/* fatal */
exit(2);
}
}
//.........这里部分代码省略.........