int main(void) { int x,y=0; char ch; printf("Press Number \n"); printf("1.child terminates before its parent.\n"); printf("2.parent terminates before child.\n"); printf("3.function is used to make parent wait.\n"); scanf("%d",&x); if(x==1) { p_child(2); } else if(x==2) { p_child(0); } else if(x==3) { printf("wait()\n"); } return 0; }
void TestArchivingBoostSharedPtrToChild() throw (Exception) { OutputFileHandler handler("archive",false); std::string archive_filename; archive_filename = handler.GetOutputDirectoryFullPath() + "shared_ptr.arch"; // Save { // Create an output archive std::ofstream ofs(archive_filename.c_str()); boost::archive::text_oarchive output_arch(ofs); boost::shared_ptr<ChildClass> p_child(new ChildClass); p_child->mTag = 11; p_child->mTagInBaseClass = 3; boost::shared_ptr<ChildClass> const p_child_for_archiving = p_child; output_arch << p_child_for_archiving; } // Load { // Create an input archive std::ifstream ifs(archive_filename.c_str(), std::ios::binary); boost::archive::text_iarchive input_arch(ifs); boost::shared_ptr<ChildClass> p_child; input_arch >> p_child; TS_ASSERT_EQUALS(p_child->mTag, 11u); TS_ASSERT_EQUALS(p_child->mTagInBaseClass, 3u); } }
int main ( void ) { for (;;) { //pid_t pid; terminate(); char *cmd = readline ("shell>"); const char s[2]= " "; char* args[15]; //char* argsBG[15]; char *token=strtok(cmd,s); int a=0; while(token!=NULL){ if(a==0){ args[a]=token; a++; } else if(a<15){ args[a]=token; //argsBG[a-1]=token; a++; } token=strtok(NULL,s); } pwd(args); if (strcmp(args[0],"pwd") == 0){ fprintf(stdout, "Current working dir: %s\n", cwd); }else if(strcmp(args[0],"cd")==0){ cd(args); }else if(strcmp(args[0],"bgkill")==0){ int WhichKill=atoi(args[1]); //printf("%i",WhichKill); int WhichPid=backGround[WhichKill].pid; if(kill(WhichPid, SIGTERM)==0){ printf("Kill program with pid %i\n",WhichPid); } //}else if(strcmp(args[0],"bg")==0){ //p_num++; //RunBack(argsBG); }else if(strcmp(args[0],"bglist")==0){ bglist(); }else if(strcmp(args[0],"stop")==0){ int WhichKill=atoi(args[1]); if(backGround[WhichKill].StatOrStop==1){ printf("Error, this program is stoped\n"); }else{ backGround[WhichKill].StatOrStop=1; int WhichPid=backGround[WhichKill].pid; if(kill(WhichPid, SIGSTOP)==0){ printf("Stop program with pid %i\n",WhichPid); } } }else if(strcmp(args[0],"start")==0){ int WhichKill=atoi(args[1]); if(backGround[WhichKill].StatOrStop==0){ printf("Error, this program is running\n"); }else{ backGround[WhichKill].StatOrStop=0; int WhichPid=backGround[WhichKill].pid; if(kill(WhichPid, SIGSTOP)==0){ printf("Stop program with pid %i\n",WhichPid); } } }else{ //printf("%s",*args); hmmpid=fork(); if(hmmpid>=0){ if(hmmpid==0){ //execvp(args[0], args); //sleep(3); p_child(args); if(strcmp(args[0],"bg")==0){ bg_child(args); } //p_child(args); }else{ if(strcmp(args[0],"bg")==0){ //waitpid(hmmpid, &status, 0); AddBG(hmmpid); }else{ wait(0); } } free (cmd); }else{ printf("OUTPUT ERROR"); } } //printf ("Got: [%s]\n", cmd); //free (cmd); } }