int sys_kill(pid_t pid, int sig) { if(sig>=0 && sig<SIGNAL_MAX && _trans_number2index[sig] != _SIGUNDEF) { struct process *dest; printk(LOG_DEBUG, "signal: kill(%d, %d)\n", pid, sig); // depending pid value, this can be a gid or a pid if(pid > 0) { dest = process_from_pid(pid); if(dest != NULL) signal_raise(dest, sig); else return -EPERM; } else { // process group pid = pid==0 ? _proc_current->pgid : -pid; signal_pgid_raise(pid, sig); } } else { return -EINVAL; } return 0; }
uint32_t proc_status_func(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) { char buf[2048]; process_t * proc = process_from_pid(node->inode); if (!proc) { /* wat */ return 0; } char state = process_is_ready(proc) ? 'R' : 'S'; sprintf(buf, "Name:\t%s\n" /* name */ "State:\t%c\n" /* yeah, do this at some point */ "Tgid:\t%d\n" /* group ? group : pid */ "Pid:\t%d\n" /* pid */ "Uid:\t%d\n" , proc->name, state, proc->group ? proc->group : proc->id, proc->id, proc->user); size_t _bsize = strlen(buf); if (offset > _bsize) return 0; if (size > _bsize - offset) size = _bsize - offset; memcpy(buffer, buf, size); return size; }
uint32_t proc_cmdline_func(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) { char buf[1024]; process_t * proc = process_from_pid(node->inode); if (!proc) { /* wat */ return 0; } buf[0] = '\0'; char * _buf = buf; char ** args = proc->cmdline; while (*args) { strcpy(_buf, *args); _buf += strlen(_buf); if (*(args+1)) { strcpy(_buf, "\036"); _buf += strlen(_buf); } args++; } size_t _bsize = strlen(buf); if (offset > _bsize) return 0; if (size > _bsize - offset) size = _bsize - offset; memcpy(buffer, buf, size); return size; }
static int sys_sbrk(int size) { process_t * proc = (process_t *)current_process; if (proc->group != 0) { proc = process_from_pid(proc->group); } spin_lock(proc->image.lock); uintptr_t ret = proc->image.heap; uintptr_t i_ret = ret; ret = (ret + 0xfff) & ~0xfff; /* Rounds ret to 0x1000 in O(1) */ proc->image.heap += (ret - i_ret) + size; while (proc->image.heap > proc->image.heap_actual) { proc->image.heap_actual += 0x1000; assert(proc->image.heap_actual % 0x1000 == 0); alloc_frame(get_page(proc->image.heap_actual, 1, current_directory), 0, 1); invalidate_tables_at(proc->image.heap_actual); } spin_unlock(proc->image.lock); return ret; }