Exemple #1
0
void openPipe(){
	currentPipe = newPipe(); // new pipe
	if(lastPipe == NULL){
		lastPipe = currentPipe;
	}

	if(!currentPipe)
		fprintf(stderr, "\n current pipe is null");
	if(!lastPipe)
		fprintf(stderr, "\n last pipe is null");


}
bool InterprocessConnection::createPipe (const String& pipeName, int timeoutMs, bool mustNotExist)
{
    disconnect();

    std::unique_ptr<NamedPipe> newPipe (new NamedPipe());

    if (newPipe->createNewPipe (pipeName, mustNotExist))
    {
        const ScopedLock sl (pipeAndSocketLock);
        pipeReceiveMessageTimeout = timeoutMs;
        initialiseWithPipe (newPipe.release());
        return true;
    }

    return false;
}
Exemple #3
0
void executePipe(char *line, char *cmd) {
	int bgFg = getFgBg(cmd);	/* fg(0) or bg(1) */
	int status;

	pid_t pid = fork();

	if(pid < 0) {
		perror("Fork error, pid < 0");
	/* parent */
	} else if(pid > 0) {
		/* set process group ID of child to self pid */
		/* will suspend when receive SIGTTIN and SIGTTOU signals */
		setpgid(pid, pid);

		/* set terminal control to new process group with child */
		tcsetpgrp(STDIN_FILENO, pid);

		/* insert process in the list */
		insertProcess(pid, bgFg, cmd);


		if(processList.current->process.status == FOREGROUND) {
			/* wait child finish */
			waitpid(pid, &status, WUNTRACED);
		}

		/* parent regains terminal control */
		tcsetpgrp(STDIN_FILENO, getpgid(0));
	/* child */
	} else {
		/* signals SIGTSTP and SIGINT will show default behavior in child */
		defaultSignals();
		
		/* set group id of child to self pid */
		/* suspend when receive signals SIGTTIN and SIGTTOUT */
		/* the child could go through exec before the parent set the group */
		setpgid(0, 0);

        int startLine = 0;	/* search begin of next expression */
        int start, end;		/* expression delimiters */
        char *previousCmd;
		
		/* while find commands between pipes */
        while(setExpressionDelimiters(line + startLine,
        	"[^| ]([^|]*[^| ])?", &start, &end)) {
        	
            previousCmd = cmd;
            
            /* get current command */
            cmd = getExpression(line + startLine, start, end, 0);
            
            /* go to next search */
            startLine += end;

			/* file input and output of pipe */
            int file[2];
            pid_t pid;

            newPipe(file, &pid);

			/* parent */
			if(pid > 0) {
				readPipe(file);
			/* child */
			} else {
				writePipe(file);
				internalExternalPipe(previousCmd, NO_JOBS_CONTROL);
			}
        }

		/* execute last command */
        internalExternalPipe(cmd, NO_JOBS_CONTROL);
    }
}