-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserapp.c
More file actions
43 lines (35 loc) · 1008 Bytes
/
userapp.c
File metadata and controls
43 lines (35 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "userapp.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
// Additional headers as needed
// Register process with kernel module
void register_process(unsigned int pid)
{
FILE* file_ptr = fopen("/proc/kmlab/status", "w");
if (file_ptr == NULL) {
printf("Error opening file '/proc/kmlab/status' when registering process\n");
exit(1);
}
/*register itself by writing PID to the /proc filesystem*/
// printf("PID being registered %d\n", pid); // for debugging verification of correct PID being registered
fprintf(file_ptr, "%d", pid);
fclose(file_ptr);
}
int main(int argc, char* argv[])
{
int __expire = 10;
time_t start_time = time(NULL);
if (argc == 2) {
__expire = atoi(argv[1]);
}
register_process(getpid());
// Terminate user application if the time is expired
while (1) {
if ((int)(time(NULL) - start_time) > __expire) {
break;
}
}
return 0;
}