Exemple #1
0
//Function handles pipeline command by checking if their is a pipe or otherwise
//passing command to stage
//Parameters are the command and the bkgd value
//returns the status from the command called
int pipelineA(CMD* c, bool bkgd){
	if(c->type == PIPE) {
		return doPipeline(c, bkgd);
	} else {
		return stageA(c, bkgd);
	}
}
Exemple #2
0
void runAMF(){
        for(i = padding; i < row; i++){
                for(j = padding; j < col; j++){
// 				  std::cout<< "Alive" << std::endl;
                        S = Sinit;
                         stageA();
                }
        }
}
Exemple #3
0
//Function that executes the pipline command by reseting file descriptors
//so that output of left is passed as input to right
//parameters are the command tree and the boolean for if the left process should
//be backgrounded
//Some of this function comes from pipe.c given in class
int doPipeline(CMD* c, bool bkgd){


    int fd[2],                  // Read and write file descriptors for pipe
	pid, status,            // Process ID and status of child
	pidTwo, statusTwo;

	//execute pipe and fork and if either fails, exit
	if (pipe(fd) || (pid = fork()) < 0) errorExit (EXIT_FAILURE);

	else if (pid == 0) {                    // Child process
	    close (fd[0]);                      //  No reading from new pipe
		if (fd[1] != 1) {                   //  stdout = write[new pipe]
			dup2 (fd[1], 1);
			close (fd[1]);
		}
	    exit(pipelineA(c->left, bkgd));    //  Overlay by i-th filter

	} else {   
		close(fd[1]);                             // Parent process
    }

    //execute a child process for the child
    if ((pidTwo = fork()) < 0) errorExit (EXIT_FAILURE);

    else if (pidTwo == 0) {                        // Child process
    	if(fd[0] != 0){
    		dup2(fd[0], 0);
    		close(fd[0]);
    	}
		exit(stageA(c->right, bkgd)); //  Overlay by last filter
    } else {
    	close(fd[0]);
    	//wait to get the status
    	waitpid(pid, &status, WUNTRACED);
    	waitpid(pidTwo, &statusTwo, WUNTRACED);
    	//set status
    	return (status > 0 && statusTwo == 0) ? 
    		setStatus(status) : setStatus(statusTwo);
    }
    //reap zombies
   	pid_t zombie;
    while((zombie = waitpid(-1, &status, WNOHANG)) > 0); //reap zombies

    return 1;

}
Exemple #4
0
void stageA(){
        findZs();
        int A1 = zMed - zMin;
        int A2 = zMed - zMax;
        if(A1 > 0 && A2 < 0){
                stageB();
        }
        else{
                S = S + 1;
                if(S <= Smax){
                        stageA();
                }
                else{
                        resImage.at<uchar>(i, j) = zMed;
                        //image.at<uchar>(i, j) = zMed;
                }
        }
}