it's midnight and i am about to fall asleep
This commit is contained in:
parent
636c6d3fef
commit
39a2de5a71
|
@ -1 +1 @@
|
|||
,winsdominoes,fedora,17.11.2024 20:23,file:///home/winsdominoes/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;
|
||||
,winsdominoes,fedora,17.11.2024 20:55,file:///home/winsdominoes/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,49 @@
|
|||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
clock_t t;
|
||||
t = clock();
|
||||
|
||||
int flag = 0;
|
||||
// Handling signal function
|
||||
void handle_signal(int signal)
|
||||
{
|
||||
// If signal is SIGINT
|
||||
if (signal == SIGQUIT)
|
||||
{
|
||||
// Set flag to its complement
|
||||
// Print the flag value
|
||||
flag = !flag;
|
||||
printf("Flag: %d\n", flag);
|
||||
}
|
||||
|
||||
if (signal == SIGINT)
|
||||
{
|
||||
t = clock() - t;
|
||||
double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
|
||||
printf("CPU Time: %f\n", t);
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Handling signal
|
||||
signal(SIGQUIT, handle_signal);
|
||||
signal(SIGINT, handle_signal);
|
||||
|
||||
// Let the program run until interrupt
|
||||
while (1)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//t = clock() - t;
|
||||
//double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
|
||||
|
||||
printf("CPU Time: %f\n", t);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
int flag = 0;
|
||||
// Handling signal function
|
||||
void handle_signal(int signal)
|
||||
{
|
||||
// If signal is SIGINT
|
||||
if (signal == SIGQUIT)
|
||||
{
|
||||
// Set flag to its complement
|
||||
// Print the flag value
|
||||
flag = !flag;
|
||||
printf("Flag: %d\n", flag);
|
||||
}
|
||||
|
||||
if (signal == SIGINT)
|
||||
{
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
clock_t t;
|
||||
t = clock();
|
||||
// Handling signal
|
||||
signal(SIGQUIT, handle_signal);
|
||||
signal(SIGINT, handle_signal);
|
||||
|
||||
// Let the program run until interrupt
|
||||
while (1)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
t = clock() - t;
|
||||
double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
|
||||
|
||||
printf("CPU Time: %f\n", t);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void handle_signal(int signal) {
|
||||
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,41 @@
|
|||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int c;
|
||||
int flag = 0;
|
||||
|
||||
/*
|
||||
THIS IS A REPLACEMENT FOR THE _KBHIT FUNCTION
|
||||
*/
|
||||
|
||||
// These structs are for saving tty parameters
|
||||
static struct termios old_term, new_term;
|
||||
|
||||
// Get parameters associated with the tty
|
||||
// Set the new tty parameters to the old one
|
||||
tcgetattr(STDIN_FILENO, &old_term);
|
||||
new_term = old_term;
|
||||
|
||||
// Set the new tty parameters to canonical mode
|
||||
new_term.c_lflag &= ~(ICANON);
|
||||
|
||||
// Set tty attributes
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_term);
|
||||
|
||||
// Get character input by user
|
||||
while ((c = getchar()) != EOF)
|
||||
{
|
||||
flag = !flag;
|
||||
printf("\n");
|
||||
printf("Flag: %d\n", flag);
|
||||
}
|
||||
|
||||
// Done retriving input
|
||||
// Set tty parameters back to old tty parameters
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &old_term);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int c;
|
||||
int flag = 0;
|
||||
|
||||
/*
|
||||
THIS IS A REPLACEMENT FOR THE _KBHIT FUNCTION
|
||||
*/
|
||||
|
||||
// These structs are for saving tty parameters
|
||||
static struct termios old_term, new_term;
|
||||
|
||||
// Get parameters associated with the tty
|
||||
// Set the new tty parameters to the old one
|
||||
tcgetattr(STDIN_FILENO, &old_term);
|
||||
new_term = old_term;
|
||||
|
||||
// Set the new tty parameters to canonical mode
|
||||
new_term.c_lflag &= ~(ICANON);
|
||||
|
||||
// Set tty attributes
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_term);
|
||||
|
||||
// Get character input by user
|
||||
while ((c = getchar()) != EOF)
|
||||
{
|
||||
flag = !flag;
|
||||
printf("Flag: %d\n", flag);
|
||||
}
|
||||
|
||||
// Done retriving input
|
||||
// Set tty parameters back to old tty parameters
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &old_term);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue