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


C++ close_pipe函数代码示例

本文整理汇总了C++中close_pipe函数的典型用法代码示例。如果您正苦于以下问题:C++ close_pipe函数的具体用法?C++ close_pipe怎么用?C++ close_pipe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: check_pipe

void    check_pipe(t_env *env)
{
  close_pipe(&env->fd.pipe, env->fd.pipefd);
  close_pipe(&env->fd.pipe2, env->fd.pipefd2);
  close_pipe(&env->fd.pipe, env->fd.pipefd);
  close_pipe(&env->fd.pipe2, env->fd.pipefd2);
}
开发者ID:MEth0,项目名称:42sh,代码行数:7,代码来源:pipe_handle.c

示例2: make_loop

void make_loop(int n, int* last_pipe, char* grammar) {
    /* last_pipe[0] = input of the recently created pipe    *
     * last_pipe[1] = output of the first pipe              */
	pid_t pid;
	if (n == 1) {
		prepare_input(last_pipe);
        prepare_output(last_pipe);
        close_pipe(last_pipe);
        return;
	}
	int next_pipe[2];
    create_pipe(next_pipe);
	switch (pid = fork()) {
		case -1:
			syserr("Error in fork()\n");
		case 0:
			prepare_input(last_pipe);
            close_pipe(last_pipe);
            prepare_output(next_pipe);
            close_pipe(next_pipe);
			execl("./worker", "./worker", grammar, NULL);
			syserr("Error in execl()\n");
		default:
            last_pipe[0] = next_pipe[0];
            make_loop(n - 1, last_pipe, grammar);
            return;
	}
}
开发者ID:ertesh,项目名称:SO,代码行数:28,代码来源:manager.c

示例3: spawn_worker

static int spawn_worker(char *cmd) 
{
	/* params struct for both workers */
	struct worker_params params;
	/* children's pids */
	pid_t c1, c2;
	int status, ret = 0;

	trim(cmd);
	params.cmd = cmd;

	if(open_pipe(params.pipe) == -1) {
		(void) fprintf(stderr, "%s: Could not create pipe\n", pgname);
		return -1;
	}

	/* We flush all our standard fd's so we'll have them empty in the workers */
	fflush(stdin);
	fflush(stdout);
	fflush(stderr);

	/* Fork execute worker */
	if((c1 = fork_function(execute, &params)) == -1) {
		(void) fprintf(stderr, "%s: Could not spawn execute worker\n", pgname);
		close_pipe(params.pipe, channel_all);
		return -1;
	}

	/* Fork format worker */
	if((c2 = fork_function(format, &params)) == -1) {
		(void) fprintf(stderr, "%s: Could not spawn format worker\n", pgname);
		/* Wait for child 1 */
		if(wait_for_child(c1) == -1) {
			(void) fprintf(stderr, "%s: Error waiting for execute worker to finish\n", pgname);
		}
		close_pipe(params.pipe, channel_all);
		return -1;
	}

	/* We need to close the pipe in parent, so that the format worker will quit working when execute's output has finished */
	close_pipe(params.pipe, channel_all);
	
	if((status = wait_for_child(c1)) != 0) {
		(void) fprintf(stderr, "%s: Execute worker returned %d\n", pgname, status);
		/* not neccessarily an error. If there was a typo in cmd don't quit the whole programm */
	//	ret = -1;
	}

	if((status = wait_for_child(c2)) != 0) {
		(void) fprintf(stderr, "%s: Format worker returned %d\n", pgname, status);
	//	ret = -1;
	}
	
	return ret;
}
开发者ID:beruns,项目名称:tuwien-osue,代码行数:55,代码来源:websh.c

示例4: prepare_process_launcher_pipes_for_manager

static void
prepare_process_launcher_pipes_for_manager (gint *command_pipe,
                                            gint *reply_pipe,
                                            GIOChannel **read_channel,
                                            GIOChannel **write_channel)
{
    close_pipe(command_pipe, MILTER_UTILS_READ_PIPE);
    close_pipe(reply_pipe, MILTER_UTILS_WRITE_PIPE);

    *write_channel = create_write_io_channel(command_pipe[MILTER_UTILS_WRITE_PIPE]);
    *read_channel = create_read_io_channel(reply_pipe[MILTER_UTILS_READ_PIPE]);
}
开发者ID:step1x2,项目名称:milter-manager,代码行数:12,代码来源:milter-manager-main.c

示例5: memset

static FILE *plugin_open(const char *path, const char *mode){
	int sfd;
	int ret;
	struct addrinfo hints,*rp,*result;
	char *url,*port,*filename;

	if(open_pipe())
		return NULL;

	if(parse_url(path,&url,&port,&filename)){
		return NULL;
	}

	memset(&hints,0,sizeof(struct addrinfo));
	hints.ai_family=AF_INET;
	hints.ai_socktype=SOCK_STREAM;
	hints.ai_protocol=0;
	if((ret=getaddrinfo(url,port,&hints,&result))){
		fprintf(stderr,"error (%s) - getaddrinfo: %s\n",path,gai_strerror(ret));
		close_pipe();
		free(port);
		return NULL;
	}
	free(url);
	free(port);

	for(rp=result;rp;rp=rp->ai_next){
		if((sfd=socket(rp->ai_family,rp->ai_socktype,rp->ai_protocol))==-1)
			continue;
		if(connect(sfd,rp->ai_addr,rp->ai_addrlen)!=-1){
			h.sfd=sfd;
			h.ffd=fdopen(sfd,mode);
			break;
		}
		close(sfd);
	}
	if(!rp){
		fprintf(stderr,"Cannot connect to: %s\n",path);
		close_pipe();
		return NULL;
	}
	freeaddrinfo(result);

	h.print_meta=1;
	if(stream_hello(filename)){
		plugin_close(NULL);
		return NULL;
	}
	free(filename);

	return h.rfd;
}
开发者ID:heckendorfc,项目名称:harp,代码行数:52,代码来源:stream.c

示例6: kexit

//turns process into zombie. if it has children, all its children go to p1
int kexit(int exitValue)
{
	int i;
	PROC *p;

	for (i = 0; i < NFD; i++)
	{
		if(running->fd[i] != 0)
			close_pipe(i);
	}

	//send children (dead or alive) to P1's orphanage
	for (i = 1; i < NPROC; i++)
	{
		p = &proc[i];
		if(p->status != FREE && p->ppid == running->pid)
		{
			p->ppid = 1;
			p->parent = &proc[1];
		}
	}

	//restore name string
	strcpy(running->name, pname[running->pid]);
	//record exitValue and become a ZOMBIE
	running->exitCode = exitValue;
	running->status = ZOMBIE;

	//wakeup parent and P1
	kwakeup(running->parent);
	kwakeup(&proc[1]);
	tswitch();
}
开发者ID:lldarrow,项目名称:CptS-460-Operating-Systems,代码行数:34,代码来源:wait.c

示例7: create_namedpipe

	static bool create_namedpipe(impl_type& impl,const String& name_)
	{
		if(impl.serv) close_pipe(impl);

		String name=make_pipename(name_);
		int fd;
		struct sockaddr_un  un;

		if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
		{
			return false;
		}

		impl.serv.reset(fd);
		unlink(name.c_str());

		socklen_t nlen=unix_sockaddr(un,name);

		if (bind(fd, (struct sockaddr *)&un, nlen) < 0)
		{
			return false;
		}

		if (listen(fd, 10) < 0)
		{
			return false;
		}

		impl.name=name_;
		return true;

	}
开发者ID:xuanya4202,项目名称:ew_base,代码行数:32,代码来源:pipe.cpp

示例8: readfr_pipe

void readfr_pipe(QSP_ARG_DECL  Pipe *pp,const char* varname)
{
	char buf[LLEN];

	if( (pp->p_flgs & READ_PIPE) == 0 ){
		sprintf(ERROR_STRING,"Can't read from  write pipe %s",pp->p_name);
		WARN(ERROR_STRING);
		return;
	}

	if( fgets(buf,LLEN,pp->p_fp) == NULL ){
		if( verbose ){
			sprintf(ERROR_STRING,
		"read failed on pipe \"%s\"",pp->p_name);
			advise(ERROR_STRING);
		}
		close_pipe(QSP_ARG  pp);
		ASSIGN_VAR(varname,"pipe_read_error");
	} else {
		/* remove trailing newline */
		if( buf[strlen(buf)-1] == '\n' )
			buf[strlen(buf)-1] = 0;
		ASSIGN_VAR(varname,buf);
	}
}
开发者ID:E-LLP,项目名称:QuIP,代码行数:25,代码来源:pipe_support.c

示例9: creat_pipe

void creat_pipe(QSP_ARG_DECL  const char *name, const char* command, const char* rw)
{
	Pipe *pp;
	int flg;

	if( *rw == 'r' ) flg=READ_PIPE;
	else if( *rw == 'w' ) flg=WRITE_PIPE;
	else {
		sprintf(ERROR_STRING,"create_pipe:  bad r/w string \"%s\"",rw);
		WARN(ERROR_STRING);
		return;
	}

	pp = new_pipe(QSP_ARG  name);
	if( pp == NO_PIPE ) return;

	pp->p_cmd = savestr(command);
	pp->p_flgs = flg;
	pp->p_fp = popen(command,rw);

	if( pp->p_fp == NULL ){
		sprintf(ERROR_STRING,
			"unable to execute command \"%s\"",command);
		WARN(ERROR_STRING);
		close_pipe(QSP_ARG  pp);
	}
}
开发者ID:E-LLP,项目名称:QuIP,代码行数:27,代码来源:pipe_support.c

示例10: signal_handler

void signal_handler(int signal_type)
{
	int i;

	if (signal_type == SIGPIPE)
		return;

	if (signal_type == SIGSEGV)
	{
		printf("*** WARNING *** - Got segmentation fault (SIGSEGV)\n");
		printf("\nPlease mail a bug report to [email protected] or\n"
			"[email protected] containing the situation\n"
			"in which this segfault occurred, gdb-output (+backtrace)\n"
			"and other possibly noteworthy information\n");
	}
	else if (signal_type == SIGTERM)
	{
		printf("*** WARNING *** - Got termination signal (SIGTERM)\n");
	}
	else if (signal_type == SIGINT)
	{
		printf("*** WARNING *** - Got interrupt signal (SIGINT)\n");
	}

	printf("Trying to shut down lav-applications (if running): ");
	for (i=0;i<NUM;i++)
		close_pipe(i);
	printf("succeeded\n");
	signal(signal_type, SIG_DFL);
}
开发者ID:AquaSoftGmbH,项目名称:mjpeg,代码行数:30,代码来源:studio.c

示例11: uv_pipe_endgame

void uv_pipe_endgame(uv_pipe_t* handle) {
  uv_err_t err;
  int status;

  if (handle->flags & UV_HANDLE_SHUTTING &&
      !(handle->flags & UV_HANDLE_SHUT) &&
      handle->write_reqs_pending == 0) {
    close_pipe(handle, &status, &err);

    if (handle->shutdown_req->cb) {
      if (status == -1) {
        LOOP->last_error = err;
      }
      handle->shutdown_req->cb(handle->shutdown_req, status);
    }
    handle->reqs_pending--;
  }

  if (handle->flags & UV_HANDLE_CLOSING &&
      handle->reqs_pending == 0) {
    assert(!(handle->flags & UV_HANDLE_CLOSED));
    handle->flags |= UV_HANDLE_CLOSED;

    if (handle->close_cb) {
      handle->close_cb((uv_handle_t*)handle);
    }

    uv_unref();
  }
}
开发者ID:CrabDude,项目名称:node,代码行数:30,代码来源:pipe.c

示例12: run_child

static void run_child(size_t cpu)
{
	struct child * self = &children[cpu];

	self->pid = getpid();
	self->sigusr1 = 0;
	self->sigusr2 = 0;
	self->sigterm = 0;

	inner_child = self;
	if (atexit(close_pipe)){
		close_pipe();
		exit(EXIT_FAILURE);
	}

	umask(0);
	/* Change directory to allow directory to be removed */
	if (chdir("/") < 0) {
		perror("Unable to chdir to \"/\"");
		exit(EXIT_FAILURE);
	}

	setup_signals();

	set_affinity(cpu);

	create_context(self);

	write_pmu(self);

	load_context(self);

	notify_parent(self, cpu);

	/* Redirect standard files to /dev/null */
	freopen( "/dev/null", "r", stdin);
	freopen( "/dev/null", "w", stdout);
	freopen( "/dev/null", "w", stderr);

	for (;;) {
		sigset_t sigmask;
		sigfillset(&sigmask);
		sigdelset(&sigmask, SIGUSR1);
		sigdelset(&sigmask, SIGUSR2);
		sigdelset(&sigmask, SIGTERM);

		if (self->sigusr1) {
			perfmon_start_child(self->ctx_fd);
			self->sigusr1 = 0;
		}

		if (self->sigusr2) {
			perfmon_stop_child(self->ctx_fd);
			self->sigusr2 = 0;
		}

		sigsuspend(&sigmask);
	}
}
开发者ID:0omega,项目名称:platform_external_oprofile,代码行数:59,代码来源:opd_perfmon.c

示例13: lclose

static int
lclose(lua_State *L) {
	HANDLE pipe = lua_touserdata(L, 1);
	if (pipe == NULL)
		return luaL_error(L, "invalid pipe");
	close_pipe(pipe);
	return 0;
}
开发者ID:cloudwu,项目名称:freeabc,代码行数:8,代码来源:pipe.c

示例14: stop_scene_detection_process

void stop_scene_detection_process(GtkWidget *widget, gpointer data)
{
	close_pipe(LAV2YUV_S);
	scene_detection_button_label = NULL;
	scene_detection_status_label = NULL;
	scene_detection_bar = NULL;
	gtk_widget_destroy(scene_detection_window);
}
开发者ID:AquaSoftGmbH,项目名称:mjpeg,代码行数:8,代码来源:lavrec_pipe.c

示例15: COMMAND_FUNC

static COMMAND_FUNC( do_closepipe )
{
	Pipe *pp;

	pp = pick_pipe("");
	if( pp == NULL ) return;

	close_pipe(QSP_ARG  pp);
}
开发者ID:jbmulligan,项目名称:quip,代码行数:9,代码来源:pipe_menu.c


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