• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ close_pipe函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: chain

int chain(char *path, char  *args[], FILE *filters, unsigned int elements)
{
	Pipe pipes[2];
	Pipe *in, *out, *tmp;
	unsigned int child;

	in = &pipes[0];
	out = &pipes[1];

	for (child = 0; child < NPROCS; child++) {
		if (child < NPROCS-1) {
			if (mk_pipe(out) != 0) {
				perror("begin");
				return -1;
			}
		}

		switch(fork()) {
		case -1:
			return -1;
		case 0:
			if (child > 0) {
				dup2(in->reader, STDIN_FILENO);
				close(in->reader);
				close(in->writer);
			}
			if (child < NPROCS-1) {
				dup2(out->writer, STDOUT_FILENO);
				close(out->writer);
				close(out->reader);
			}
			if (execv(path, args) == -1) {
				perror("begin");
				exit(1);
			};
		default:
			if (child > 0)
				close_pipe(in);
		}

		/* patch up arguments */
		if (child == 0 || child >= elements) {
			free(path);
			path = get_name(filters);
			if (path == NULL) {
				fprintf(stderr, "begin: Unexpected end of filter list\n");
				return -1;
			}
			args[0] = path;
		}
		tmp = in;
		in = out;
		out = tmp;
	}
	return 0;
}
开发者ID:edwardt,项目名称:Pipeline-Sort,代码行数:56,代码来源:pipe_util.c


示例17: connection_free

static void connection_free(Connection *c) {
        assert(c);

        if (c->context)
                set_remove(c->context->connections, c);

        sd_event_source_unref(c->server_event_source);
        sd_event_source_unref(c->client_event_source);

        if (c->server_fd >= 0)
                close_nointr_nofail(c->server_fd);
        if (c->client_fd >= 0)
                close_nointr_nofail(c->client_fd);

        close_pipe(c->server_to_client_buffer);
        close_pipe(c->client_to_server_buffer);

        free(c);
}
开发者ID:ariscop,项目名称:systemd,代码行数:19,代码来源:socket-proxyd.c


示例18: spawn_sorts

/* creates an array containing all the PIDs of the child processes */
void spawn_sorts(int **in_pipe, int **out_pipe)
{
	//Spawn all the sort processes
	process_array = malloc(sizeof(pid_t) * num_sorts);
	pid_t pid;
        int i;
        for (i = 0; i < num_sorts; i++){
                create_pipe(in_pipe[i]);
                create_pipe(out_pipe[i]);  
                switch(pid = fork()){
                        case -1: //Oops case
                                puke_and_exit("Forking error\n");
                        case 0: //Child case
			        close(STDIN_FILENO);
			        close(STDOUT_FILENO);
			        if (in_pipe[i][0] != STDIN_FILENO) {	//Defensive check
					if (dup2(in_pipe[i][0], STDIN_FILENO) ==
					    -1)
						puke_and_exit("dup2 0");
				}
				/* Bind stdout to out_pipe*/
				close_pipe(out_pipe[i][0]);	//close read end of output pipe
				if (out_pipe[i][1] != STDOUT_FILENO) {	//Defensive check
					if (dup2(out_pipe[i][1], STDOUT_FILENO) ==
					    -1)
						puke_and_exit("dup2 1");
				}
                                /* 
                                Pipes from previously-spawned children are still open in this child
                                Close them and close the duplicate pipes just created by dup2 
                                */
                                close_pipes_array(in_pipe, i+1);
                                close_pipes_array(out_pipe, i+1);
                                execlp("sort", "sort", (char *)NULL);
                        default: //Parent case
                                process_array[i] = pid;
                                close_pipe(in_pipe[i][0]);
                		close_pipe(out_pipe[i][1]);
                                break; 
                }
        }
}
开发者ID:davidmerrick,项目名称:Classes,代码行数:43,代码来源:uniqify.c


示例19: run_shell_cmd

static int run_shell_cmd(menu_t* menu, char* cmd) {
#ifndef __MINGW32__
  int in[2],out[2],err[2];

  mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_LIBMENU_ConsoleRun,cmd);
  if(mpriv->child) {
    mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_AChildIsAlreadyRunning);
    return 0;
  }

  pipe(in);
  pipe(out);
  pipe(err);

  mpriv->child = fork();
  if(mpriv->child < 0) {
    mp_msg(MSGT_GLOBAL,MSGL_ERR,MSGTR_LIBMENU_ForkFailed);
    close_pipe(in);
    close_pipe(out);
    close_pipe(err);
    return 0;
  }
  if(!mpriv->child) { // Chlid process
    int err_fd = dup(2);
    FILE* errf = fdopen(err_fd,"w");
    // Bind the std fd to our pipes
    dup2(in[0],0);
    dup2(out[1],1);
    dup2(err[1],2);
    execl("/bin/sh","sh","-c",cmd,(void*)NULL);
    fprintf(errf,"exec failed : %s\n",strerror(errno));
    exit(1);
  }
  // MPlayer
  mpriv->child_fd[0] = in[1];
  mpriv->child_fd[1] = out[0];
  mpriv->child_fd[2] = err[0];
  mpriv->prompt = mpriv->child_prompt;
  //add_line(mpriv,"Child process started");
#endif
  return 1;
}
开发者ID:AlexanderDenkMA,项目名称:TypeChef-mplayerAnalysis,代码行数:42,代码来源:menu_console.c


示例20: main

main(int argc, char *argv[])
{ 
    int pid, cmd, i;
    char name[64];
    ucolor = 0;
    clearScreen(UMODE);
    printf("enter main() : argc = %d\n", argc);
    for (i=0; i<argc; i++)
        printf("argv[%d] = %s\n", i, argv[i]);

    while(1){
        pid = getpid();
        color = ucolor ? ucolor:0x000B + (pid % 5);// avoid black on black baground
        cmd?resetCursor(UMODE):1;
        printf("----------------------------------------------\n");
        printf("I am proc %din U mode: segment=%x\n", pid, (pid+1)*0x1000);
        show_menu();
        printf("Command ? ");
        getCurPos(UMODE);
        printf("                                                                      \n");
        setCurPos(ux_col,uy_row,UMODE);
        gets(name);
        clearScreenRegion(K_X_PRINT_OFFSET,80,U_Y_PRINT_OFFSET-1,24,UMODE);
        if (name[0]==0) 
            continue;

        cmd = find_cmd(name);
        
        getCurPos(UMODE);
        setCurPos(K_X_PRINT_OFFSET,U_Y_PRINT_OFFSET,UMODE);
        switch(cmd){
            case 0 : do_getpid();   break;
            case 1 : ps();          break;
            case 2 : chname();      break;
            case 3 : kmode();       break;
            case 4 : kswitch();     break;
            case 5 : wait();        break;
            case 6 : exit();        break;
            case 7 : fork();        break;
            case 8 : exec();        break;
            case 9 : ucolor = chcolor();     break;

            case 10: pipe();        break;
            case 11: pfd();         break;
            case 12: read_pipe();   break;
            case 13: write_pipe();  break;
            case 14: close_pipe();  break;
            
            default: invalid(name); break;
        }
        setCurPos(ux_col,uy_row,UMODE);
    }
}
开发者ID:vternal3,项目名称:OSkernal,代码行数:53,代码来源:u1.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ close_socket函数代码示例发布时间:2022-05-30
下一篇:
C++ close_on_exec函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap