コード例 #1
0
ファイル: proc.c プロジェクト: jorrit/vpncwatch
/* stop the command */
void stop_cmd(char *cmd, int cmdpid) {
    int s, i;

    syslog(LOG_NOTICE, "stopping %s", cmd);

    /* try SIGTERM, then SIGKILL */
    for (s = SIGTERM; s <= SIGKILL; s -= (SIGTERM - SIGKILL)) {
        if (!kill(cmdpid, s)) {
            return;
        }

        for (i = 0; i < 30; i++) {
            if (!is_running(cmdpid)) {
                break;
            }

            sleep(1);
        }

        if (!is_running(cmdpid)) {
            return;
        }
    }

    if (is_running(cmdpid)) {
        syslog(LOG_ERR, "%s (%d) didn't die!", cmd, cmdpid);
    }

    return;
}
コード例 #2
0
ファイル: base_thread.cpp プロジェクト: fpstovall/nrtb_beta
void thread::detach(bool yes)
{
	if (yes)
	{
		if (is_running())
		{
			pthread_detach(mytid);
		}
		else
		{
			start_detached = true;
		};
	}
	else
	{
		if (is_running()) 
		{
			throw attr_change_failed_exception();
		}
		else
		{
			start_detached = false;
		};
	};
};
コード例 #3
0
void ImpersonateSession::wait() const {
  if (!is_valid() || !is_running()) {
    return;
  }
  ThreadControlBlock* block = thread_->get_control_block();
  while (is_running()) {
    uint64_t demand = block->task_complete_cond_.acquire_ticket();
    if (!is_running()) {
      break;
    }
    block->task_complete_cond_.timedwait(demand, 100000ULL);
  }
}
コード例 #4
0
ファイル: runner.cpp プロジェクト: rotanov/Spawner
void runner::enumerate_threads_(std::function<void(handle_t)> on_thread) {
    if (!is_running()) {
        return;
    }
    HANDLE thread_snapshot_h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
    if (thread_snapshot_h == handle_default_value) {
        return;
    }
    THREADENTRY32 thread_entry;
    thread_entry.dwSize = sizeof(thread_entry);
    if (!Thread32First(thread_snapshot_h, &thread_entry)) {
        return;
    }
    do {
        if (thread_entry.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) +
            sizeof(thread_entry.th32OwnerProcessID) && thread_entry.th32OwnerProcessID == process_info.dwProcessId) {
            handle_t handle = OpenThread(THREAD_ALL_ACCESS, FALSE, thread_entry.th32ThreadID);
            if (on_thread) {
                on_thread(handle);
            }
            CloseHandle(handle);
        }
        thread_entry.dwSize = sizeof(thread_entry);
    } while (Thread32Next(thread_snapshot_h, &thread_entry));
    CloseHandle(thread_snapshot_h);
}
コード例 #5
0
ファイル: server.cpp プロジェクト: lsem/eks-httpserver
Server::~Server()
{
    if (is_running())
    {
        Stop();
    }
}
コード例 #6
0
static struct task_struct* pfair_schedule(struct task_struct * prev)
{
	struct pfair_state* state = &__get_cpu_var(pfair_state);
	int blocks;
	struct task_struct* next = NULL;

	raw_spin_lock(&pfair_lock);

	blocks  = is_realtime(prev) && !is_running(prev);

	if (state->local && safe_to_schedule(state->local, state->cpu))
		next = state->local;

	if (prev != next) {
		tsk_rt(prev)->scheduled_on = NO_CPU;
		if (next)
			tsk_rt(next)->scheduled_on = state->cpu;
	}

	raw_spin_unlock(&pfair_lock);

	if (next)
		TRACE_TASK(next, "scheduled rel=%lu at %lu (%llu)\n",
			   tsk_pfair(next)->release, pfair_time, litmus_clock());
	else if (is_realtime(prev))
		TRACE("Becomes idle at %lu (%llu)\n", pfair_time, litmus_clock());

	return next;
}
コード例 #7
0
ファイル: timer.hpp プロジェクト: tanisman/IncludeOS
inline void Timer::stop() {
  if(is_running())
  {
    Timers::stop(id_);
    id_ = Timers::UNUSED_ID;
  }
}
コード例 #8
0
ファイル: sysipc_threads.cpp プロジェクト: nasacj/woodycxx
 //-------------------------------------------------------------------------------------------------------------
 void process::kill_child()
 {
     if ( is_running() )
     {
         kill( child_pid, SIGTERM );
     }
 }
コード例 #9
0
ファイル: quash.c プロジェクト: ddreilin/Quash
/**
 * Quash entry point
 *
 * @param argc argument count from the command line
 * @param argv argument vector from the command line
 * @return program exit status
 */
int main(int argc, char** argv){
  //Command holder argument
  command_t cmd;

  //initialize variables.
  strcpy(home, "/home");
  strcpy(path, "/home:/home/ddreilin/EECS_678/Project1/Quash");
  strcat(path, ":/home/hkaustin/EECS_678/project1-quash/quash/Quash");
  strcat(path, ":/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/lib64/openmpi/bin/:/opt/smlnj/bin/");

  getcwd(cwd, sizeof(cwd));
  start();

  puts("Welcome to Quash!");
  puts("Type \"exit\" or \"quit\" to quit");

  // Main execution loop
  while (is_running() && get_command(&cmd, stdin)) {
    // NOTE: I would not recommend keeping anything inside the body of
    // this while loop. It is just an example.
    // The commands should be parsed, then executed.
    manager(&cmd);
  }
  return EXIT_SUCCESS;
}
コード例 #10
0
ファイル: main.cpp プロジェクト: DongWenHu/schedule_center
int main(int argc, char* argv[])
{
    if (is_running())
    {
        printf("There is already a instance running!\n");
        return -1;
    }

    if ( !mpsp::config_mgr::get().init() ||
         !mpsp::device_mgr::get().init() ||
         !mpsp::wx_account_mgr::get().init()||
         !mpsp::tasks_mgr::get().init())
    {
        return -1;
    }
    mpsp::main_task s(mpsp::task_processor::get().get_io_service());
    mpsp::task_processor::get().push_task(boost::bind(&mpsp::main_task::start, &s));

    mpsp::task_processor::get().start();

    try
    {
        boost::interprocess::message_queue::remove(k_msg_queue_name);
    }
    catch (...)
    {

    }

    return 0;
}
コード例 #11
0
ファイル: base_thread.cpp プロジェクト: fpstovall/nrtb_beta
void thread::start()
{
	if (!is_running())
	{
		int results;
		// Build the attributes we'll use for this
		pthread_attr_t attribs;
		pthread_attr_init(&attribs);
		if (start_detached)
		{
			pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED);
		}
		else
		{
			pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_JOINABLE);
		};
		// start the thread by using our predefined entry point
		results = pthread_create(&mytid,&attribs,startpoint,this);
		// Could we start? Warning: pthread_create returns false if succesful.
		if (results)
		{
			throw no_start_exception();
		};
	}
	else
	{
		// not good; we are already active!
		throw already_running_exception();
	};
};
コード例 #12
0
ファイル: launcher.c プロジェクト: flaboy/erltookit
int is_running(){
    printf("1 %s\n",options.daemon);
    if(waitpid(proc_stat.pid, &proc_stat.result, WNOHANG)==0){
        return 1;
    }else if(options.daemon){
        FILE * fd;
        printf("2 %s\n",options.daemon);
        if(0==(fd=fopen(options.daemon,"r"))){
            return 0;
        }else{
            int new_pid=0;
            char buff[50];
            memset(buff, 0, sizeof(buff));
            fread(&buff,20,1,fd);
            new_pid = strtol(buff, NULL, 10);
            fclose(fd);
            if(proc_stat.pid != new_pid){
                printf("new pid=%d, old=%d\n",new_pid, proc_stat.pid);
                proc_stat.pid = new_pid;
                return is_running();
            }else{
                return 0;
            }
        }
    }else{
        return 0;
    }
}
コード例 #13
0
ファイル: printing.c プロジェクト: clerkma/texlive-mobile
void print_rule_dimen(scaled d)
{
if(is_running(d))
print_char('*');
else
print_scaled(d);
}
コード例 #14
0
            void start() {
                int server_fd = _server_sock.raw();
                const timeval delay = {0, 10000};
                fd_set server_fd_set;
                fd_set readable_fd_set;
                FD_ZERO(&server_fd_set);
                FD_SET(server_fd, &server_fd_set);
                readable_fd_set = server_fd_set;

                while (is_running()) {
                    timeval t = delay;
                    int selected = ::select(server_fd + 1, &readable_fd_set, NULL, NULL, &t);

                    if (selected == -1) {
                        perror("select");
                        std::abort();
                    }
                    else if (selected > 0 && FD_ISSET(server_fd, &readable_fd_set)) {
                        TCPSocket* p_new_sock = _server_sock.accept();
                        _client_socks.push_back(p_new_sock);
                    }

                    // reset readable_fd_set and t
                    readable_fd_set = server_fd_set;
                }
            }
コード例 #15
0
ファイル: client.hpp プロジェクト: linxuanwei/Bex
        // 发送数据
        bool send(char const* buffer, std::size_t size)
        {
            if (is_running())
                return session_->send(buffer, size);

            return false;
        }
コード例 #16
0
ファイル: client.hpp プロジェクト: linxuanwei/Bex
        // 阻塞式连接
        bool connect(endpoint const& addr)
        {
            if (is_running() || async_connecting_.is_set())
                return false;

            socket_ptr sp = protocol_type::alloc_socket(ios_, *opts_, ec_);
            if (ec_)
                return false;

            sp->lowest_layer().connect(addr, ec_);
            if (ec_) 
                return false;

            protocol_traits_type::handshake(sp, ssl::stream_base::client, ec_);
            if (ec_) 
                return false;

            session_ = make_shared_ptr<session_type, allocator>();
            session_->initialize(sp, opts_, callback_);

            // 启动工作线程
            mstrand_service_.startup(opts_->workthread_count);
            running_.set();
            return true;
        }
コード例 #17
0
ファイル: server.hpp プロジェクト: maydayzm/Bex
        // 启动
        bool startup(endpoint const& addr, std::size_t listen_count = 1)
        {
            if (is_running())
                return false;

            acceptor_.open(addr.protocol(), ec_);
            if (ec_) return false;

            acceptor_.set_option(socket_base::reuse_address(false), ec_);
            if (ec_) return false;

            acceptor_.bind(addr, ec_);
            if (ec_) return false;

            acceptor_.listen(socket_base::max_connections, ec_);
            if (ec_) return false;

            accept_count_ = listen_count;
            for (std::size_t i = 0; i < listen_count; ++i)
                async_accept();

            // 启动工作线程
            use_service<mstrand_service_type>(ios_).startup(opts_->workthread_count);

            running_.set();
            return true;
        }
コード例 #18
0
ファイル: sqlite_source.cpp プロジェクト: CCJY/engine-1
void sqlite_source::check_not_running() const
throw(
	std::logic_error)
{
	if (is_running())
		throw std::logic_error("The source is immediately running.");
}
コード例 #19
0
ファイル: SpawnUnix.cpp プロジェクト: Agilack/vle
    bool get(std::string *output, std::string *error)
    {
        if (m_finish) {
            return false;
        }

        is_running();

        std::vector < char > buffer;
        buffer.reserve(BUFSIZ);

        int result;

        if ((result = input_timeout(m_pipeout[0], m_waitchildtimeout)) == -1)
            return false;

        if (result) {
            int size = read(m_pipeout[0], &buffer[0], BUFSIZ);
            if (size > 0 and output) {
                output->append(&buffer[0], size);
            }
        }

        if ((result = input_timeout(m_pipeerr[0], m_waitchildtimeout)) == -1)
            return false;

        if (result) {
            int size = read(m_pipeerr[0], &buffer[0], BUFSIZ);
            if (size > 0 and error) {
                error->append(&buffer[0], size);
            }
        }

        return true;
    }
コード例 #20
0
/*	Prepare a task for running in RT mode
 */
static void psnedf_task_new(struct task_struct * t, int on_rq, int is_scheduled)
{
	rt_domain_t* 		edf  = task_edf(t);
	psnedf_domain_t* 	pedf = task_pedf(t);
	unsigned long		flags;

	TRACE_TASK(t, "psn edf: task new, cpu = %d\n",
		   t->rt_param.task_params.cpu);

	/* setup job parameters */
	release_at(t, litmus_clock());

	/* The task should be running in the queue, otherwise signal
	 * code will try to wake it up with fatal consequences.
	 */
	raw_readyq_lock_irqsave(&pedf->slock, flags);
	if (is_scheduled) {
		/* there shouldn't be anything else scheduled at the time */
		BUG_ON(pedf->scheduled);
		pedf->scheduled = t;
	} else {
		/* !is_scheduled means it is not scheduled right now, but it
		 * does not mean that it is suspended. If it is not suspended,
		 * it still needs to be requeued. If it is suspended, there is
		 * nothing that we need to do as it will be handled by the
		 * wake_up() handler. */
		if (is_running(t)) {
			requeue(t, edf);
			/* maybe we have to reschedule */
			psnedf_preempt_check(pedf);
		}
	}
	raw_readyq_unlock_irqrestore(&pedf->slock, flags);
}
コード例 #21
0
ファイル: launcher.c プロジェクト: flaboy/erltookit
int wait_for_service(){

    if(options.test_port){

        struct sockaddr_in service;
        service.sin_family = PF_INET;
        service.sin_addr.s_addr = inet_addr("127.0.0.1");
        service.sin_port = htons(options.test_port);
        int conn = -1;

	struct timeval tv = { 0, 100 * 1000 };

        while(1){
            int sockfd = socket(PF_INET, SOCK_STREAM, 0);
            if(sockfd < 0) exit(1);
            select(0, NULL, NULL, NULL, &tv);
            conn = connect(sockfd, &service, sizeof(service));
            close(sockfd);
            if(conn==0){
                return 1;
            }else if(!is_running()){
                return 0;
            }
        }
    }

    return 1;
}
コード例 #22
0
ファイル: writer_binary.cpp プロジェクト: katsuster/omxil-mf
void writer_binary::worker_main::write_file(int fd)
{
	port_buffer pb_in;
	ssize_t nwritten;
	OMX_ERRORTYPE result;

	while (is_running()) {
		if (is_request_flush()) {
			return;
		}

		result = in_port->pop_buffer(&pb_in);
		if (result != OMX_ErrorNone) {
			errprint("in_port_video.pop_buffer().\n");
			continue;
		}

		if (pb_in.remain() == 0) {
			//no data
			in_port->fill_buffer_done(&pb_in);
			continue;
		}

		nwritten = write(fd, pb_in.get_ptr(), pb_in.remain());
		if (nwritten == -1) {
			//Error
			errprint("write() failed.\n");
			break;
		}

		pb_in.skip(nwritten);
		in_port->empty_buffer_done(&pb_in);
	}
}
コード例 #23
0
ファイル: infcall.c プロジェクト: ArmstrongJ/insight-debugger
static struct gdb_exception
run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
{
  volatile struct gdb_exception e;
  int saved_in_infcall = call_thread->control.in_infcall;
  ptid_t call_thread_ptid = call_thread->ptid;

  call_thread->control.in_infcall = 1;

  clear_proceed_status ();

  disable_watchpoints_before_interactive_call_start ();

  /* We want stop_registers, please...  */
  call_thread->control.proceed_to_finish = 1;

  TRY_CATCH (e, RETURN_MASK_ALL)
    {
      proceed (real_pc, TARGET_SIGNAL_0, 0);

      /* Inferior function calls are always synchronous, even if the
	 target supports asynchronous execution.  Do here what
	 `proceed' itself does in sync mode.  */
      if (target_can_async_p () && is_running (inferior_ptid))
	{
	  wait_for_inferior ();
	  normal_stop ();
	}
    }
コード例 #24
0
ファイル: is_running.hpp プロジェクト: LocutusOfBorg/poedit
inline bool is_running(const child_handle &p, int & exit_code)
{
    std::error_code ec;
    bool b = is_running(p, exit_code, ec);
    boost::process::detail::throw_error(ec, "waitpid(2) failed in is_running");
    return b;
}
コード例 #25
0
ファイル: Subsystem.hpp プロジェクト: Croydon/code
    /// Start a subsystem by name
    ///
    /// If the subsystem is already running, no change will
    /// be done.
    ///
    /// The subsystem will be started during the next tick.
    /// This means there might be some delay.
    ///
    /// @throws NoSuchSubsystem
    void start(const std::string &sub) {
        Subsystem::Register::EnsureExist(sub);

        next_tick([&, sub]() {
            if (!is_running(sub))
                subsystems[sub] = Subsystem::Register::Get(sub)();
        });
    }
コード例 #26
0
ファイル: mio_loop.cpp プロジェクト: wsxiaoys/MsgIO
void loop_impl::start( int num )
{
    if (!is_running()) {
        _is_running = true;
    }

    add_thread(num);
}
コード例 #27
0
ファイル: Subsystem.hpp プロジェクト: Croydon/code
    /// Stop a subsystem by name
    ///
    /// If the subsystem is not running, no change will be
    /// applied.
    ///
    /// The subsystem will be started during the next tick.
    /// This means there might be some delay.
    ///
    /// @throws NoSuchSubsystem
    void stop(const std::string &sub) {
        Subsystem::Register::EnsureExist(sub);

        next_tick([&, sub]() {
            if (is_running(sub))
                subsystems.erase(sub);
        });
    }
コード例 #28
0
void gpu_worker(void *arg)
{
	hs_worker *worker_arg = (hs_worker *) arg;

	bind_to_cpu(worker_arg);

	init_cuda(worker_arg->device_id);

//	printf("GPU I am id:%d\n", worker_arg->worker_id);

	pthread_mutex_lock(&worker_arg->mutex);
	worker_arg->initialized = 1;
	pthread_cond_signal(&worker_arg->ready);
	pthread_mutex_unlock(&worker_arg->mutex);

	_task_t task;
	while (is_running())
	{
		lock_queue(worker_arg->task_queue);

		task = pop_task(worker_arg->task_queue);

		if (task == NULL)
		{
			if (is_running())
				sleep_worker(worker_arg);

			unlock_queue(worker_arg->task_queue);
			continue;
		}

		unlock_queue(worker_arg->task_queue);

		if ((task->task->arch_type & worker_arg->arch) != worker_arg->arch)
		{
			push_task(worker_arg->task_queue, task);
			continue;
		}

		execute_task(worker_arg, task);
	}

	deinit_cuda();

	pthread_exit((void*) 0);
}
コード例 #29
0
void NetworkQueue::start()
{
  if( !is_running() && !m_transactions.isEmpty() )
  {
    m_current_index = 0;
    send_next_frame();
  }
}
コード例 #30
0
bool thread_pool::push( function_type func )
{
	if ( false == is_running() )
		return false;
	work_queue_content.pushback(func);
	thread_wait_condition.notify_one();

	return true;
}