Lab6
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
/*
|
||||
On startup, the agent program creates the file
|
||||
/var/run/agent.pid and writes its PID into the file. It then reads
|
||||
the contents of a file called text.txt, prints it on the console and
|
||||
finally sleeps indefinitely
|
||||
*/
|
||||
FILE *file = fopen("text.txt", "w");
|
||||
FILE *filePid = fopen("agent.txt", "w");
|
||||
fputc(getpid(), filePid);
|
||||
fclose(filePid);
|
||||
fclose(file);
|
||||
char pid_str[10];
|
||||
fgets(pid_str, sizeof(pid_str), file);
|
||||
fclose(file);
|
||||
|
||||
FILE *text_file = fopen("text.txt", "r");
|
||||
if (text_file == NULL) {
|
||||
printf("Error opening text.txt\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char c;
|
||||
while ((c = fgetc(text_file))!= EOF)
|
||||
printf("%c", c);
|
||||
|
||||
fclose(text_file);
|
||||
|
||||
printf("\nSleeping indefinitely...\n");
|
||||
while (1)
|
||||
sleep(1);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by emil on 01.10.2024.
|
||||
//
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
/*
|
||||
* Write a C program that prints “Hello world!” an infinite number
|
||||
of times.
|
||||
Run the program, and kill it by pressing (Ctrl+C). Which signal
|
||||
did the process receive? Can we handle it? Can the process ignore
|
||||
the signal?
|
||||
Run the program, and kill it by pressing (Ctrl+\). Which signal
|
||||
did the process receive? Can we handle it? Can the process ignore
|
||||
the signal? In Ubuntu, set core dump size via ulimit -c
|
||||
unlimited. The core dump file is in /var/lib/apport/coredump/.
|
||||
Check the log file /var/log/apport.log for core dump file name.
|
||||
Run the program in the background (&) and redirect stdout to a
|
||||
file output.txt, kill the process by sending the signal “SIGTERM”
|
||||
via “kill -s SIGTERM pid ” command. Can we handle the
|
||||
signal? Can the process ignore the signal? Send the signal
|
||||
“SIGKILL” if the program does not terminate politely.
|
||||
30 / 58
|
||||
*/
|
||||
|
||||
|
||||
while (1)
|
||||
printf("Hello world!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user