From d8487e000d8afb05d366620bdaf886d560939178 Mon Sep 17 00:00:00 2001 From: FILIPPONE Jerome <jerome@filippone.fr> Date: Tue, 19 Nov 2024 04:38:40 +0000 Subject: [PATCH] Upload New File --- .../SEANCE_02-19NOV2024/sf1.c | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 UE701/SEMESTRE__2024_25/SEANCE_02-19NOV2024/sf1.c diff --git a/UE701/SEMESTRE__2024_25/SEANCE_02-19NOV2024/sf1.c b/UE701/SEMESTRE__2024_25/SEANCE_02-19NOV2024/sf1.c new file mode 100644 index 0000000..756befd --- /dev/null +++ b/UE701/SEMESTRE__2024_25/SEANCE_02-19NOV2024/sf1.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> +#include <sys/syscall.h> +#include <sys/types.h> + +// Print the current date and time in C +int main(void) +{ + // variables to store the date and time components + int hours, minutes, seconds, day, month, year; + + // `time_t` is an arithmetic time type + time_t now; + + // Obtain current time + // `time()` returns the current time of the system as a `time_t` value + time(&now); + + // Convert to local time format and print to stdout + printf("Today is %s", ctime(&now)); + + // localtime converts a `time_t` value to calendar time and + // returns a pointer to a `tm` structure with its members + // filled with the corresponding values + struct tm *local = localtime(&now); + + hours = local->tm_hour; // get hours since midnight (0-23) + minutes = local->tm_min; // get minutes passed after the hour (0-59) + seconds = local->tm_sec; // get seconds passed after a minute (0-59) + + day = local->tm_mday; // get day of month (1 to 31) + month = local->tm_mon + 1; // get month of year (0 to 11) + year = local->tm_year + 1900; // get year since 1900 + + // print local time + if (hours < 12) { // before midday + printf("Time is %02d:%02d:%02d am\n", hours, minutes, seconds); + } + else { // after midday + printf("Time is %02d:%02d:%02d pm\n", hours - 12, minutes, seconds); + } + + // print the current date + printf("Date is: %02d/%02d/%d\n", day, month, year); + + unsigned cpu, node; + + // Get current CPU core and NUMA node via system call + // Note this has no glibc wrapper so we must call it directly + syscall(SYS_getcpu, &cpu, &node, NULL); + + // Display information + printf("This program is running on CPU core %u and NUMA node %u.\n\n", cpu, node); + + return 0; +} + -- GitLab