Esempio n. 1
0
void actuator_setstate(int devno, int state) {
  if (state) {
      debug("[external actuator plugin] device %d running command: %s\n",devno,ext_act_cfg.extactuatoron[devno]);
      myexec(ext_act_cfg.extactuatoron[devno],1);
    } else {
      debug("[external actuator plugin] device %d running command: %s\n",devno,ext_act_cfg.extactuatoroff[devno]);
      myexec(ext_act_cfg.extactuatoroff[devno],1);
    }
}
Esempio n. 2
0
File: u1.c Progetto: B-Rich/CptS460
main()
{ 
  char name[64]; int cmd;
  /* resetVideo();*/
  while(1){
       pid = get_pid();
       printf("==============================================\n");
       printf("I am task %d in Umode at segment=%x\n", pid, getcs());

       show_menu();
       printf("Command ? ");
       mgets(name); 
       if (name[0]==0) 
           continue;

       cmd = find_cmd(name);
       switch(cmd){
           case 0 : get_pid();  break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : mywait();   break;
           case 6 : myexit();   break;
           case 7 : ufork();    break;
           case 8 : myexec("/u2");  break;
           case 9 : sin();      break;
           case 10 : sout();    break;
           default: invalid(name); break;
       }
  }
}
Esempio n. 3
0
int main(){
	
	list lista = NULL;
	char input[254];
	int pid;
	int count=0;
	int status;
	int fd[2]; //pipe fd for process sinc
	struct pollfd fds; //struct for poll

	
	//opening the pipe for pollin
	if((pipe(fd)) == -1){
		perror("Pipe");
		return(EXIT_FAILURE);
	}
	fds.fd = fd[0];
	fds.events=POLLIN;
	
	fgets(input,254,stdin);

	while (input[0]!='\n') {
		
		if ( (pid = fork()) == -1) {
			printf("fork fail\n");
			return(EXIT_FAILURE);
		}
		
		if (pid == 0) {	//child

			char *currComm = malloc(sizeof(char)*strlen(input));
			strcpy(currComm,input);
			poll(&fds,1,-1); //struct poll, size of fds array and -1 for block until interrupt call
							//wait until all processes are ready
			
			myexec(currComm);
			
			perror(currComm);
			return(EXIT_FAILURE);
		}
		count++;
		insert(&lista, input, pid);

		fgets(input,254,stdin);
	}
	pid_t arrival[count];
	
	//tell to all the processes to start
	write(fd[1], "g", 1);
	
	for(int i=0;i<count;i++){
		arrival[i]=wait(&status);
	}
	
	for(int i=0;i<count;i++){
		printNamePid(arrival[i], lista, i);
	}

	return 0;
}
Esempio n. 4
0
main()
{ 
  char name[64]; int cmd;
  int pid;
  while(1){
       pid = getpid();
       printf("==============================================\n");
       printf("Das ist prozess %d im Umode segment=%x\n", pid, getcs());
       show_menu();
       printf("Command ? ");
       gets(name); 
       if (name[0]==0) 
           continue;

       cmd = find_cmd(name);
       switch(cmd){
           case 0 : getpid();  break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : mywait();   break;
           case 6 : myexit();   break;
           case 7 : ufork();    break;
           case 8 : myexec("/bin/u1"); break; 
           case 9 : sin(); break;
           case 10: sout(); break;
          default: invalid(name); break;
       }
  }
}
Esempio n. 5
0
int main()
{
	char cmdStr[50] = { '0' };
	char printStr[10240] = { '0' };
	scanf("%s", cmdStr);
	myexec(cmdStr, printStr);

	printf("%s", printStr);

	char searchStr[20];
	scanf("%s", searchStr);

	char *p = searchWord(searchStr, printStr);
	if (p != NULL)
	{
		printf("%s ´æÔÚ", searchStr);
	}
	else
	{
		printf("%s ²»´æÔÚ", searchStr);
	}

	system("pause");
	return 0;
}
Esempio n. 6
0
int main(int argc, char *argv[]){
	
	if (argc != 2) {
		fprintf(stderr, "Error: Expected 1 parameter.\n"
				"Usage: %s <pathname>\n", argv[0]);
		return(EXIT_FAILURE);
	}
	
	char *path = argv[1]; //indirizzo del file da leggere
	char *cmdString; //riga di codice
	size_t n;
	ssize_t read;
	
	
	FILE *f;
	int pid;
	
	//open the file
	
	f = fopen(path, "r");
	if (f == NULL){
		printf("cannot open the file\n");
		exit(EXIT_FAILURE);
	}
	
	//Gets all the line and execute
	
	while (( read = getline(&cmdString, &n, f))!=-1){
		
		if (!strncmp(cmdString,"#",1)){
			continue;
		}
		
		if ( (pid = fork()) == -1) {
			return(EXIT_FAILURE);
		}
		
		if (pid == 0) {	//child
			
			myexec(cmdString);
			return(EXIT_FAILURE);
			
		} else {
			wait(NULL);	//wait for child to terminate
		}
	}
	fclose(f);
	return 0;
}
Esempio n. 7
0
int main(int argc, char *argv[]){
  DIR           *d;
  struct dirent *dir;
  char *path;
  char args[1];
  int fd[2]; //pipe fd for process sinc


  list lista = NULL;
  //    char input[254];
  int pid;
  //int count=0;
  int status;

  struct pollfd fds; //struct for poll

  d = opendir(".");
  if(d==NULL){
      printf ("Non riesco ad aprire la directory corrente");
      exit(1);

  }

  //opening the pipe for pollin
  if((pipe(fd)) == -1){
      perror("Pipe");
      return(EXIT_FAILURE);
  }
  fds.fd = fd[0];
  fds.events=POLLIN;




//    fgets(input,254,stdin);

    while ((dir = readdir(d)) != NULL) {
        switch (pid=fork()) {
            case -1:
                printf("fork fail\n");
                return(EXIT_FAILURE);
                break;
            case 0:
                if(strncmp(dir->d_name, ".", 1)){//ignora i file nascosti
                    if(eseguibile(dir->d_name)&&palindroma(dir->d_name)){
                        //printf("%s è eseguibile\n", dir->d_name);
                        path=malloc(strlen(dir->d_name)+3);
                        strcpy(path, "./");
                        strcat(path, dir->d_name);
                        printf("%s è il path \n", path);
                        poll(&fds,1,-1); //struct poll, size of fds array and -1 for block until interrupt call
                            //wait until all processes are ready

                        myexec(path);

                        perror(path);
                        return(EXIT_FAILURE);
                    }
                }
        }//end switch

    }
  write(fd[1], "g", 1);



return(0);
}