Created
November 11, 2016 18:57
-
-
Save yodalee/44731c22b0e884f6c0be02e2a03f19c2 to your computer and use it in GitHub Desktop.
AOS HW2 test our system call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <linux/kernel.h> | |
#include <sys/syscall.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/wait.h> | |
#include "dummysyscall.h" | |
void print_prinfo(prinfo_t *prinfo) | |
{ | |
fprintf(stderr, "uid = %ld run program %s\n", | |
prinfo->uid, prinfo->comm); | |
fprintf(stderr, "pid = %d in state %ld with nice value = %ld\n", | |
prinfo->pid, prinfo->state, prinfo->nice); | |
fprintf(stderr, "parent %d -> current %d\n", prinfo->parent_pid, prinfo->pid); | |
fprintf(stderr, "youngest child %d, younger_sibling_pid %d, older_sibling_pid %d\n", | |
prinfo->youngest_child_pid, prinfo->younger_sibling_pid, prinfo->older_sibling_pid); | |
fprintf(stderr, "process started at %ld\n", prinfo->start_time); | |
fprintf(stderr, "time: user %ld, sys %ld, cutime %ld, cstime %ld\n", | |
prinfo->user_time, prinfo->sys_time, prinfo->cutime, prinfo->cstime); | |
} | |
int main() | |
{ | |
prinfo_t *p_prinfo = (prinfo_t *)malloc(sizeof(prinfo_t)); | |
memset(p_prinfo, 0, sizeof(prinfo_t)); | |
printf("Invoking 'dummy syscall' system call\n"); | |
printf("====================================\n"); | |
// Run for a while so that we have time in utime/stime | |
unsigned int sum = 0; | |
for (int i = 0; i < 100000000; ++i) { | |
sum += i; | |
} | |
pid_t pid; | |
// Create a child so we have child process. | |
if ((pid = fork()) == 0) { | |
sleep(10); | |
} else { | |
long ret_status = syscall(330, p_prinfo); // 330 for dummy system call | |
if (ret_status != 0) { | |
printf("System call 'dummy syscall' did not execute as expected\n"); | |
return ret_status; | |
} | |
print_prinfo(p_prinfo); | |
wait(NULL); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment