Beispiel #1
0
int main() {
	auto adam=Person::makePerson("Adam");
	adam->print(std::cout);
	auto eve=Person::makePerson("Eve");
	eve->print(std::cout);
	addson("Cain",adam, eve);
	addson("Abel",adam, eve);
	addson("Seth",adam, eve);
	adam->print(std::cout);
	eve->print(std::cout);
	// how to have Cain kill Abel?
	{
		auto abel=eve->findChild("Abel");
		eve->killChild(abel);
		adam->killChild(abel);
		abel->print(std::cout);
	}
	eve->print(std::cout);
	// how can we kill Adam and Eve?
	{
		adam->killMe();
		adam->print(std::cout);
		adam.reset();
	}
	eve->print(std::cout);
	auto cain=eve->findChild("Cain");
	if (cain) cain->print(std::cout);
	eve->killMe(); // avoid memory leak
	eve->print(std::cout);
	eve.reset();
}
Beispiel #2
0
/**
 * 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_t cmd; //< Command holder argument
      
    start();
    struct sigaction NULL_sa;
    struct sigaction sa;
    sigset_t mask_set;
    sigfillset(&mask_set);
    sigdelset(&mask_set,SIGINT);
    sigdelset(&mask_set,SIGTSTP);
    sa.sa_handler = catchChild;
    sigprocmask(SIG_SETMASK, &mask_set, NULL);
    //TODO: this is involved withe the error 10 problem. Removing it remedies the issue for now but breaks other things.
    sigaction(SIGCHLD, &sa,NULL);//child termination calls catchChild;

    setenv( "WKDIR", getenv("HOME"), 1 );

    puts("hOi! Welcome to Quash!");

    // Main execution loop
    while (is_running()) 
    {
        // 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.
        if( !get_command(&cmd, stdin) );
        else if (!strcmp(cmd.cmdstr, "q")||!strcmp(cmd.cmdstr, "exit")||!strcmp(cmd.cmdstr, "quit"))
            terminate(); // Exit Quash
        else if(!strcmp(cmd.execArgs[0], "set"))
            set(cmd);//set environment variables
        else if(!strcmp(cmd.execArgs[0], "echo"))
            echo(cmd);//echos environment variables
        else if(!strcmp(cmd.execArgs[0], "pwd"))
            pwd(cmd);//prints current working directory
        else if(!strcmp(cmd.execArgs[0], "cd"))
            cd(cmd);//changes the working directory
        else if(!strcmp(cmd.execArgs[0], "jobs"))
            jobs();//prints out a list of currently running jobs
        else if(!strcmp(cmd.execArgs[0], "kill"))
            killChild(cmd);//kills specified job
        else if (!strcmp(cmd.execArgs[0], "wait"))
            sleep(atoi(cmd.execArgs[1]));
        else if (strchr(cmd.cmdstr,'|')!= NULL)
            exec_pipes(cmd);//executes piped commands
        else 
            exec_cmd(cmd);//executes normal commands
    }

    return EXIT_SUCCESS;
}