void child() { fprintf(stdout, "Process %d with parent %d start\n", sched_getpid(), sched_getppid()); long long i; for (i = 0; i < 1000000000; i++) { if ((i % 100000000) == 0) { fprintf(stdout, "Process %d at %d\n", sched_getpid(), i); } } sched_exit(sched_getpid()); }
void child1() { fprintf(stderr,"HIIII child here! my pid is %d and my parent is %d\n",sched_getpid(),sched_getppid()); long long i; for (i = 0; i < 1000000000; i++) { if (i%100000000==0) { fprintf(stderr,"pid=%d, i=%lld, ticks=%d\n",sched_getpid(),i,sched_gettick()); } } sched_exit(85); }
void parent() { fprintf(stdout, "Process %d with parent %d start\n", sched_getpid(), sched_getppid()); int i, code; for (i = -2; i < 2; i += 1) { sched_wait(&code); fprintf(stdout, "Process %d exited\n", code); } return; }
void parent() { fprintf(stderr,"parent hello world my pid is %d and my parent is %d\n",sched_getpid(),sched_getppid()); long long i; for (i = 0; i < 1000000000; i++) { if (i%100000000==0) { fprintf(stderr,"pid=%d, i=%lld, ticks=%d\n",sched_getpid(),i,sched_gettick()); } } int ret; sched_wait(&ret); printf("one child returned %d\n",ret); sched_wait(&ret); printf("another child returned %d\n",ret); sched_exit(0); }
// INT 80h Handler, kernel entry. void int_80() { if(krn) { return; } krn++; int systemCall = kernel_buffer[0]; int fd = kernel_buffer[1]; int buffer = kernel_buffer[2]; int count = kernel_buffer[3]; int i, j; Process * current; Process * p; int inode; int _fd; // Yeah, wanna know why we don't access an array directly? ... Because of big bugs we might have. switch(systemCall) { case READY: kernel_buffer[KERNEL_RETURN] = kernel_ready(); break; case WRITE: current = getp(); kernel_buffer[KERNEL_RETURN] = fd_write(current->file_descriptors[fd],(char *)buffer,count); break; case READ: current = getp(); kernel_buffer[KERNEL_RETURN] = fd_read(current->file_descriptors[fd],(char *)buffer,count); break; case MKFIFO: _fd = process_getfreefd(); fd = fd_open(_FD_FIFO, (void *)kernel_buffer[1],kernel_buffer[2]); if(_fd != -1 && fd != -1) { getp()->file_descriptors[_fd] = fd; kernel_buffer[KERNEL_RETURN] = _fd; } else { kernel_buffer[KERNEL_RETURN] = -1; } break; case OPEN: _fd = process_getfreefd(); fd = fd_open(_FD_FILE, (void *) kernel_buffer[1], kernel_buffer[2]); if(_fd != -1 && fd >= 0) { getp()->file_descriptors[_fd] = fd; kernel_buffer[KERNEL_RETURN] = _fd; } else { kernel_buffer[KERNEL_RETURN] = fd; } break; case CLOSE: kernel_buffer[KERNEL_RETURN] = fd_close(getp()->file_descriptors[fd]); break; case PCREATE: kernel_buffer[KERNEL_RETURN] = sched_pcreate(kernel_buffer[1],kernel_buffer[2],kernel_buffer[3]); break; case PRUN: kernel_buffer[KERNEL_RETURN] = sched_prun(kernel_buffer[1]); break; case PDUP2: kernel_buffer[KERNEL_RETURN] = sched_pdup2(kernel_buffer[1],kernel_buffer[2],kernel_buffer[3]); break; case GETPID: kernel_buffer[KERNEL_RETURN] = sched_getpid(); break; case WAITPID: kernel_buffer[KERNEL_RETURN] = sched_waitpid(kernel_buffer[1]); break; case PTICKS: kernel_buffer[KERNEL_RETURN] = (int) storage_index(); break; case PNAME: p = process_getbypid(kernel_buffer[1]); if(p == NULL) { kernel_buffer[KERNEL_RETURN] = (int) NULL; } else { kernel_buffer[KERNEL_RETURN] = (int) p->name; } break; case PSTATUS: p = process_getbypid(kernel_buffer[1]); if(p == NULL) { kernel_buffer[KERNEL_RETURN] = (int) -1; } else { kernel_buffer[KERNEL_RETURN] = (int) p->state; } break; case PPRIORITY: p = process_getbypid(kernel_buffer[1]); if(p == NULL) { kernel_buffer[KERNEL_RETURN] = (int) -1; } else { kernel_buffer[KERNEL_RETURN] = (int) p->priority; } break; case PGID: p = process_getbypid(kernel_buffer[1]); if(p == NULL) { kernel_buffer[KERNEL_RETURN] = (int) -1; } else { kernel_buffer[KERNEL_RETURN] = (int) p->gid; } break; case PGETPID_AT: p = process_getbypindex(kernel_buffer[1]); if (p->state != -1) { kernel_buffer[KERNEL_RETURN] = (int) p->pid; } else { kernel_buffer[KERNEL_RETURN] = -1; } break; case KILL: kernel_buffer[KERNEL_RETURN - 1] = kernel_buffer[1]; kernel_buffer[KERNEL_RETURN - 2] = kernel_buffer[2]; break; case PSETP: p = process_getbypid(kernel_buffer[1]); if(p == NULL) { kernel_buffer[KERNEL_RETURN] = (int) -1; } else { if(kernel_buffer[2] <= 4 && kernel_buffer[2] >= 0) { p->priority = kernel_buffer[2]; } kernel_buffer[KERNEL_RETURN] = (int) p->gid; } break; case SETSCHED: sched_set_mode(kernel_buffer[1]); break; case PWD: kernel_buffer[KERNEL_RETURN] = (int) fs_pwd(); break; case CD: kernel_buffer[KERNEL_RETURN] = (int) fs_cd(kernel_buffer[1]); break; case FINFO: fs_finfo(kernel_buffer[1], kernel_buffer[2]); break; case MOUNT: fs_init(); break; case MKDIR: kernel_buffer[KERNEL_RETURN] = (int) fs_mkdir(kernel_buffer[1],current_ttyc()->pwd); break; case RM: inode = fs_indir(kernel_buffer[1],current_ttyc()->pwd); if (inode) { kernel_buffer[KERNEL_RETURN] = (int) fs_rm(inode,0); } else { kernel_buffer[KERNEL_RETURN] = ERR_NO_EXIST; } break; case GETUID: if(kernel_buffer[1] == 0) { kernel_buffer[KERNEL_RETURN] = (int) current_ttyc()->uid; } else { kernel_buffer[KERNEL_RETURN] = (int) user_exists(kernel_buffer[1]); } break; case GETGID: if(kernel_buffer[1] == 0) { kernel_buffer[KERNEL_RETURN] = (int) user_gid(current_ttyc()->uid); } else { kernel_buffer[KERNEL_RETURN] = (int) user_gid(kernel_buffer[1]); } break; case MAKEUSER: kernel_buffer[KERNEL_RETURN] = user_create(kernel_buffer[1], kernel_buffer[2], user_gid(current_ttyc()->uid)); break; case SETGID: kernel_buffer[KERNEL_RETURN] = user_setgid(kernel_buffer[1], kernel_buffer[2]); break; case UDELETE: kernel_buffer[KERNEL_RETURN] = user_delete(kernel_buffer[1]); break; case UEXISTS: kernel_buffer[KERNEL_RETURN] = user_exists(kernel_buffer[1]); break; case ULOGIN: kernel_buffer[KERNEL_RETURN] = user_login(kernel_buffer[1], kernel_buffer[2]); break; case ULOGOUT: kernel_buffer[KERNEL_RETURN] = user_logout(); break; case CHOWN: kernel_buffer[KERNEL_RETURN] = fs_chown(kernel_buffer[1], kernel_buffer[2]); break; case CHMOD: kernel_buffer[KERNEL_RETURN] = fs_chmod(kernel_buffer[1], kernel_buffer[2]); break; case GETOWN: kernel_buffer[KERNEL_RETURN] = fs_getown(kernel_buffer[1]); break; case GETMOD: kernel_buffer[KERNEL_RETURN] = fs_getmod(kernel_buffer[1]); break; case CP: kernel_buffer[KERNEL_RETURN] = fs_cp(kernel_buffer[1], kernel_buffer[2], current_ttyc()->pwd, current_ttyc()->pwd); break; case MV: kernel_buffer[KERNEL_RETURN] = fs_mv(kernel_buffer[1], kernel_buffer[2], current_ttyc()->pwd); break; case LINK: kernel_buffer[KERNEL_RETURN] = fs_open_link(kernel_buffer[1], kernel_buffer[2], current_ttyc()->pwd); break; case FSSTAT: kernel_buffer[KERNEL_RETURN] = fs_stat(kernel_buffer[1]); break; case SLEEP: kernel_buffer[KERNEL_RETURN] = scheduler_sleep(kernel_buffer[1]); break; default: break; } krn--; }
void init() { signal(SIGUSR1, &signal1); printf("[Init][Pid: %d] Scheduler Testing Program\n", sched_getpid()); sched_nice(-20); for (int i = 0; i < 15; i++) { if (sched_fork() == 0) { printf("[Child][Pid: %d] Parent Pid: %d\n", sched_getpid(), sched_getppid()); sched_nice(-19 + i); struct timespec start, stop; clock_gettime(CLOCK_REALTIME, &start); for (long int j = 0; j < 1000000000; j++); clock_gettime(CLOCK_REALTIME, &stop); printf("[Child][Pid: %d] Execution Complete. Took %ld Seconds.\n", sched_getpid(), (long int)(stop.tv_sec - start.tv_sec)); sched_exit(i); printf("[Child][Pid: %d] This Will Never Get Executed\n", sched_getpid()); } } printf("[Init][Pid: %d] Process Information\n", sched_getpid()); sched_ps(); for (int i = 0; i < 15; i++) { int returncode; int cc = sched_wait(&returncode); printf("[Init][Pid: %d] Child Returned [%d] With Exit Code [%d]\n", sched_getpid(), cc, returncode); } int returncode; int cc = sched_wait(&returncode); printf("[Init][Pid: %d] Calling Wait With No Children Returns [%d]\n", sched_getpid(), cc); sched_sleep(&wait1); for (int i = 0; i < 15; i++) { if (sched_fork() == 0) { printf("[Child][Pid: %d] Parent Pid: %d\n", sched_getpid(), sched_getppid()); sched_nice(-19 + i); if (i % 2 == 1) sched_sleep(&wait1); else sched_sleep(&wait2); printf("[Child][Pid: %d] Execution Complete.\n", sched_getpid()); sched_exit(i); } } for (int i = 0; i < 1000000000; i++); printf("[Init][Pid: %d] Process Information\n", sched_getpid()); sched_ps(); printf("Wakeup 2\n"); sched_wakeup(&wait2); printf("Wakeup 1\n"); sched_wakeup(&wait1); for (int i = 0; i < 15; i++) { int returncode; int cc = sched_wait(&returncode); printf("[Init][Pid: %d] Child Returned [%d] With Exit Code [%d]\n", sched_getpid(), cc, returncode); } printf("[Init][Pid: %d] Exiting Testing Program. Passing Control Back To Idle\n", sched_getpid()); sched_exit(0); }