[feature] CI workflow
This commit is contained in:
parent
36677fb428
commit
e158bfc04a
9
.gitea/workflows/main-build.yaml
Normal file
9
.gitea/workflows/main-build.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
name: main-build
|
||||
run-name: actor: ${{ gitea.actor }}
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
main-compile:
|
||||
runs-on: ubuntue-latest
|
||||
steps:
|
||||
- run: echo "Workflow is running"
|
||||
@ -1,4 +1,3 @@
|
||||
<<<<<<< HEAD
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
|
||||
|
||||
# Set the project name
|
||||
@ -9,32 +8,15 @@ find_package(CURL REQUIRED)
|
||||
|
||||
# add the executable
|
||||
ADD_EXECUTABLE(main
|
||||
<<<<<<< HEAD
|
||||
|
||||
# OSX Files
|
||||
source/osx/cpu.c
|
||||
source/osx/ram.c
|
||||
source/osx/disk.c
|
||||
source/osx/device.c
|
||||
|
||||
|
||||
# Linux Files
|
||||
source/linux/cpu.c
|
||||
source/linux/ram.c
|
||||
source/linux/disk.c
|
||||
source/linux/device.c
|
||||
|
||||
# Main File
|
||||
source/main.c
|
||||
|
||||
source/lib.c
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(main PRIVATE CURL::libcurl)
|
||||
TARGET_INCLUDE_DIRECTORIES(main PRIVATE source/lib/osx source/lib/linux)
|
||||
=======
|
||||
source/main.c
|
||||
source/lib/osx/cpu.c
|
||||
source/lib.c
|
||||
)
|
||||
|
||||
target_include_directories(main PRIVATE source/lib/osx)
|
||||
>>>>>>> 7e64275 (maocs now returns cpu name)
|
||||
|
||||
@ -1 +0,0 @@
|
||||
build/compile_commands.json
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: device.c
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 07/17/25 23:14:35
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: YOUR NAME (),
|
||||
* Organization:
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
|
||||
void cpu_name();
|
||||
void cpu_freq();
|
||||
void cpu_temperature();
|
||||
void *cpu_i(void *a);
|
||||
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
|
||||
void *cpu_name();
|
||||
void *cpu_threads();
|
||||
void *cpu_info();
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
||||
int frequency;
|
||||
char* name;
|
||||
int threads;
|
||||
|
||||
} cpu_s;
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -1,16 +0,0 @@
|
||||
#ifndef DEVICE_H
|
||||
#define DEVICE_H
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
typedef struct{
|
||||
char* name;
|
||||
} device_s;
|
||||
|
||||
extern device_s device_info;
|
||||
|
||||
void* get_device_info();
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -1,17 +0,0 @@
|
||||
#ifndef DISK_H
|
||||
#define DISK_H
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
void* disk_size();
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __gnu_linux__
|
||||
typedef struct {
|
||||
long long size;
|
||||
short name;
|
||||
} disk_s;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -1,24 +0,0 @@
|
||||
#ifndef RAM_H
|
||||
#define RAM_H
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
void* size();
|
||||
void* av_size();
|
||||
void* ram_info();
|
||||
|
||||
typedef struct {
|
||||
long double total;
|
||||
long double available;
|
||||
} ram_s;
|
||||
|
||||
|
||||
#endif
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
void size();
|
||||
void av_size();
|
||||
void *ram_i(void *a);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
523
source/lib.c
Normal file
523
source/lib.c
Normal file
@ -0,0 +1,523 @@
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <math.h>
|
||||
|
||||
#define MAXC 1024
|
||||
#define MAXC_CHAR 256
|
||||
|
||||
typedef struct {
|
||||
|
||||
int frequency;
|
||||
char* name;
|
||||
int threads;
|
||||
|
||||
} cpu_s;
|
||||
|
||||
typedef struct {
|
||||
|
||||
unsigned long mem_size;
|
||||
|
||||
} ram;
|
||||
|
||||
unsigned long get_total(void);
|
||||
unsigned long get_usage(void);
|
||||
long device_up_time(void);
|
||||
void name();
|
||||
void temperature();
|
||||
void freq();
|
||||
void *cpu_i(void *a);
|
||||
void *ram_i(void *a);
|
||||
void cpu_name(void);
|
||||
void cpu_temperature(unsigned short delay);
|
||||
char* cpu_frequency(void);
|
||||
|
||||
cpu_s _cpu;
|
||||
|
||||
void *cpu_name(){
|
||||
int buffer_size = 256;
|
||||
char cpu_name[buffer_size];
|
||||
|
||||
printf("Opening the CPU information files");
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp)
|
||||
printf("can't open /proc/cpuinfo");
|
||||
|
||||
char line[buffer_size];
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (strncmp(line, "model name", 10) == 0)
|
||||
{
|
||||
char *colon = strchr(line, ':');
|
||||
if (colon)
|
||||
{
|
||||
snprintf(cpu_name, buffer_size, "%s", colon + 2);
|
||||
cpu_name[strcspn(cpu_name, "\n")] = 0;
|
||||
int err = fclose(fp);
|
||||
if (err != 0)
|
||||
printf("error closing /proc/cpuinfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_cpu.name = cpu_name;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* cpu_frequency() {
|
||||
char* buffer = malloc(MAXC_CHAR);
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp) {
|
||||
printf("can't open /proc/cpuinfo");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(buffer, MAXC_CHAR, fp)) {
|
||||
if (strstr(buffer, "cpu MHz") != NULL)
|
||||
{
|
||||
char *colon = strchr(buffer, ':');
|
||||
if (colon)
|
||||
{
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
snprintf(buffer, MAXC_CHAR, "%s", colon);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *cpu_i(void *a){
|
||||
printf("thread is working");
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
unsigned long get_total(void){
|
||||
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
return total_ram;
|
||||
|
||||
}
|
||||
|
||||
unsigned long get_usage(void)
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
long free_ram = info.freeram * info.mem_unit;
|
||||
|
||||
return total_ram - free_ram;
|
||||
}
|
||||
|
||||
void *ram_i(void *a){
|
||||
|
||||
printf("thread is working");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cpu_name(void)
|
||||
{
|
||||
int buffer_size = 256;
|
||||
char cpu_name[buffer_size];
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp)
|
||||
printf("can't open /proc/cpuinfo");
|
||||
|
||||
char line[buffer_size];
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (strncmp(line, "model name", 10) == 0)
|
||||
{
|
||||
char *colon = strchr(line, ':');
|
||||
if (colon)
|
||||
{
|
||||
snprintf(cpu_name, buffer_size, "%s", colon + 2);
|
||||
cpu_name[strcspn(cpu_name, "\n")] = 0;
|
||||
int err = fclose(fp);
|
||||
if (err != 0)
|
||||
printf("error closing /proc/cpuinfo");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s", cpu_name);
|
||||
snprintf(cpu_name, buffer_size, "%s", cpu_name);
|
||||
}
|
||||
|
||||
void cpu_temperature(unsigned short delay)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
sleep(delay);
|
||||
FILE *pf = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
|
||||
if (!pf)
|
||||
printf("error reading /proc/cpuinfo");
|
||||
|
||||
char buffer[MAXC];
|
||||
while (fgets(buffer, sizeof(buffer), pf))
|
||||
{
|
||||
int a = atoi(buffer);
|
||||
a /= 1000;
|
||||
printf("%dC\n", a);
|
||||
fflush(stdout);
|
||||
}
|
||||
fclose(pf);
|
||||
}
|
||||
}
|
||||
|
||||
char* cpu_frequency(void) {
|
||||
char* buffer = malloc(MAXC_CHAR);
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp) {
|
||||
printf("can't open /proc/cpuinfo");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(buffer, MAXC_CHAR, fp)) {
|
||||
if (strstr(buffer, "cpu MHz") != NULL)
|
||||
{
|
||||
char *colon = strchr(buffer, ':');
|
||||
if (colon)
|
||||
{
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
snprintf(buffer, MAXC_CHAR, "%s", colon);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned long get_total(void){
|
||||
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
return total_ram;
|
||||
|
||||
}
|
||||
|
||||
unsigned long get_usage(void)
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
long free_ram = info.freeram * info.mem_unit;
|
||||
|
||||
return total_ram - free_ram;
|
||||
}
|
||||
|
||||
long device_up_time(void){
|
||||
struct sysinfo info;
|
||||
if (sysinfo(&info) == -1)
|
||||
perror("sysinfo");
|
||||
|
||||
return info.uptime;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <cjson/cJSON.h>
|
||||
|
||||
#define CONVERT_BYTES_TO_GIGABYTES 107374182
|
||||
#define D 1073741824
|
||||
|
||||
typedef struct {
|
||||
|
||||
cpu_s* cpu;
|
||||
ram_s* ram;
|
||||
disk_s* disk;
|
||||
device_s* device;
|
||||
|
||||
} info;
|
||||
|
||||
typedef struct {
|
||||
unsigned long mem_size;
|
||||
} ram;
|
||||
|
||||
void* cpu_name();
|
||||
void* cpu_thread_count();
|
||||
unsigned long get_total(void);
|
||||
unsigned long get_usage(void);
|
||||
long device_up_time(void);
|
||||
float cpu_frequency(void);
|
||||
char* cpu_name(void);
|
||||
void size();
|
||||
void av_size();
|
||||
void* ram_i();
|
||||
|
||||
ram_s data;
|
||||
cpu_s cpu;
|
||||
device_s device_info;
|
||||
|
||||
void *cpu_name() {
|
||||
|
||||
char *name;
|
||||
size_t len = 0;
|
||||
|
||||
if (sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0) < 0)
|
||||
perror("errorn in assigning the size for the cpu name variable\n");
|
||||
|
||||
name = malloc(len);
|
||||
|
||||
if(sysctlbyname("machdep.cpu.brand_string", name, &len, NULL, 0) < 0){
|
||||
perror("error in assigning the value to the cpu name variable\n");
|
||||
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cpu.name = name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *cpu_threads() {
|
||||
|
||||
int count;
|
||||
size_t len = sizeof(count);
|
||||
if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the cpu threads count\n");
|
||||
|
||||
cpu.threads = count;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *cpu_info() {
|
||||
|
||||
cpu_threads();
|
||||
cpu_name();
|
||||
|
||||
printf("cpu name: %s\ncpu threads: %d\n", cpu.name, cpu.threads);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void *device_name(){
|
||||
|
||||
char *name;
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("kern.hostname", NULL, &size, NULL, 0) < 0)
|
||||
perror("failed retrieving the hostname: \n");
|
||||
|
||||
name = malloc(size);
|
||||
|
||||
if(sysctlbyname("kern.hostname", name, &size, NULL, 0) < 0){
|
||||
perror("failed retrieving the hostname: \n");
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device_info.name = name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void *device_model(){
|
||||
|
||||
char *model_name;
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("hw.model", NULL, &size, NULL, 0) < 0)
|
||||
perror("failed retrieving the hostname: \n");
|
||||
|
||||
model_name = malloc(size);
|
||||
|
||||
if(sysctlbyname("hw.model", model_name, &size, NULL, 0) < 0){
|
||||
perror("failed retrieving the hostname: \n");
|
||||
free(model_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device_info.model = model_name;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void *device_up_time()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *device_os_version() {
|
||||
|
||||
char *os_version;
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("kern.ostype", NULL, &size, NULL, 0) < 0)
|
||||
perror("failed retrieving the hostname: \n");
|
||||
|
||||
os_version = malloc(size);
|
||||
|
||||
if(sysctlbyname("kern.ostype", os_version, &size, NULL, 0) < 0){
|
||||
perror("failed retrieving the os version: \n");
|
||||
free(os_version);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device_info.model = os_version;
|
||||
return NULL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void *get_device_info() {
|
||||
device_name();
|
||||
device_model();
|
||||
printf("device name: %s\ndevice model: %s\n", device_info.name, device_info.model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void size() {
|
||||
int64_t size;
|
||||
size_t len = sizeof(size);
|
||||
if (sysctlbyname("hw.memsize", &size, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the memory size");
|
||||
|
||||
data.total = size / D;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void av_size() {
|
||||
int64_t size;
|
||||
size_t len = sizeof(size);
|
||||
if (sysctlbyname("hw.memsize_usable", &size, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the available memory size");
|
||||
|
||||
data.available = size / D;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ram_info() {
|
||||
size();
|
||||
av_size();
|
||||
|
||||
printf("available ram: %LF\n", data.available);
|
||||
printf("total ram: %LF\n", data.total);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* ram_i(){
|
||||
|
||||
printf("thread is working");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
float cpu_frequency(void){
|
||||
uint64_t freq = 0;
|
||||
size_t size = sizeof(freq);
|
||||
|
||||
if (sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0) < 0)
|
||||
{
|
||||
perror("sysctl");
|
||||
}
|
||||
return freq;
|
||||
}
|
||||
|
||||
char* cpu_name(void){
|
||||
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("machdep.cpu.brand_string", NULL, &size, NULL, 0) < 0)
|
||||
perror("sysctl");
|
||||
|
||||
|
||||
char *name = malloc(size);
|
||||
|
||||
if(sysctlbyname("machdep.cpu.brand_string", &name, &size, NULL, 0) < 0){
|
||||
perror("sysctl");
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
long device_up_time(void){
|
||||
|
||||
struct timeval boottime;
|
||||
size_t len = sizeof(boottime);
|
||||
|
||||
if (sysctlbyname("kern.boottime", &boottime, len, NULL, 0) == -1){
|
||||
perror("sysctl error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long get_usage(void) {
|
||||
|
||||
struct rusage usage;
|
||||
if(0 == getrusage(RUSAGE_SELF, &usage))
|
||||
return usage.ru_maxrss / CONVERT_BYTES_TO_GIGABYTES ;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long get_mem(void){
|
||||
|
||||
int mib[2];
|
||||
size_t size;
|
||||
uint64_t ram_size;
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_MEMSIZE;
|
||||
|
||||
size = sizeof(ram_size);
|
||||
if (sysctl(mib, 2, &ram_size, &size, NULL, 0) == -1) {
|
||||
perror("sysctl");
|
||||
}
|
||||
|
||||
return ram_size;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
59
source/lib.h
Normal file
59
source/lib.h
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef LIB_H
|
||||
#define LIB_H
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
typedef struct{
|
||||
char* name;
|
||||
} device_s;
|
||||
|
||||
typedef struct {
|
||||
|
||||
int frequency;
|
||||
char* name;
|
||||
int threads;
|
||||
|
||||
} cpu_s;
|
||||
|
||||
typedef struct {
|
||||
long double total;
|
||||
long double available;
|
||||
} ram_s;
|
||||
|
||||
typedef struct {
|
||||
long long size;
|
||||
short name;
|
||||
} disk_s;
|
||||
|
||||
extern device_s device_info;
|
||||
|
||||
void* get_device_info();
|
||||
void* disk_size();
|
||||
void* size();
|
||||
void* av_size();
|
||||
void* ram_info();
|
||||
|
||||
|
||||
float cpu_frequency(void);
|
||||
char* cpu_name(void);
|
||||
void *cpu_name();
|
||||
void *cpu_threads();
|
||||
void *cpu_info();
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
void cpu_name();
|
||||
void cpu_freq();
|
||||
void cpu_temperature();
|
||||
void *cpu_i(void *a);
|
||||
void size();
|
||||
void av_size();
|
||||
void *ram_i(void *a);
|
||||
float cpu_freq(void);
|
||||
char* cpu_name(void);
|
||||
void cpu_temperature(void);
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,97 +0,0 @@
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MAXC 1024
|
||||
#define MAXC_CHAR 256
|
||||
|
||||
void cpu_name(void);
|
||||
void cpu_temperature(unsigned short delay);
|
||||
char* cpu_frequency(void);
|
||||
|
||||
void cpu_name(void)
|
||||
{
|
||||
int buffer_size = 256;
|
||||
char cpu_name[buffer_size];
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp)
|
||||
printf("can't open /proc/cpuinfo");
|
||||
|
||||
char line[buffer_size];
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (strncmp(line, "model name", 10) == 0)
|
||||
{
|
||||
char *colon = strchr(line, ':');
|
||||
if (colon)
|
||||
{
|
||||
snprintf(cpu_name, buffer_size, "%s", colon + 2);
|
||||
cpu_name[strcspn(cpu_name, "\n")] = 0;
|
||||
int err = fclose(fp);
|
||||
if (err != 0)
|
||||
printf("error closing /proc/cpuinfo");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s", cpu_name);
|
||||
snprintf(cpu_name, buffer_size, "%s", cpu_name);
|
||||
}
|
||||
|
||||
void cpu_temperature(unsigned short delay)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
sleep(delay);
|
||||
FILE *pf = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
|
||||
if (!pf)
|
||||
printf("error reading /proc/cpuinfo");
|
||||
|
||||
char buffer[MAXC];
|
||||
while (fgets(buffer, sizeof(buffer), pf))
|
||||
{
|
||||
int a = atoi(buffer);
|
||||
a /= 1000;
|
||||
printf("%dC\n", a);
|
||||
fflush(stdout);
|
||||
}
|
||||
fclose(pf);
|
||||
}
|
||||
}
|
||||
|
||||
char* cpu_frequency(void) {
|
||||
char* buffer = malloc(MAXC_CHAR);
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp) {
|
||||
printf("can't open /proc/cpuinfo");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(buffer, MAXC_CHAR, fp)) {
|
||||
if (strstr(buffer, "cpu MHz") != NULL)
|
||||
{
|
||||
char *colon = strchr(buffer, ':');
|
||||
if (colon)
|
||||
{
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
snprintf(buffer, MAXC_CHAR, "%s", colon);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,11 +0,0 @@
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
float cpu_freq(void);
|
||||
char* cpu_name(void);
|
||||
void cpu_temperature(void);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: general.c
|
||||
*
|
||||
* Description: Retrieving basic information about the device
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 05/08/2025 22:22:00
|
||||
* Revision: none
|
||||
* Compiler: clang
|
||||
*
|
||||
* Author: nasr,
|
||||
* Organization: synf
|
||||
*
|
||||
* ===================================================================================== */
|
||||
|
||||
// OSX
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
long device_up_time(void);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long device_up_time(void){
|
||||
|
||||
struct timeval boottime;
|
||||
size_t len = sizeof(boottime);
|
||||
|
||||
if (sysctlbyname("kern.boottime", &boottime, len, NULL, 0) == -1){
|
||||
perror("sysctl error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// GNU LINUX
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
long device_up_time(void);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
printf("The total uptime is (seconds): %lu", device_up_time());
|
||||
return 0;
|
||||
}
|
||||
|
||||
long device_up_time(void)
|
||||
{
|
||||
struct sysinfo info;
|
||||
if (sysinfo(&info) == -1)
|
||||
perror("sysinfo");
|
||||
|
||||
return info.uptime;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: disk.c
|
||||
*
|
||||
* Description: retrieving disk information from the device
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 04/08/2025 01:33:30
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: nasr
|
||||
* Organization: synf
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
<<<<<<< HEAD:source/lib/linux/disk.c
|
||||
|
||||
typedef struct {
|
||||
long size;
|
||||
=======
|
||||
void disk_size();
|
||||
|
||||
|
||||
typedef struct {
|
||||
long total_disk_size;
|
||||
>>>>>>> 1095ca1 (added the device file):source/disk.c
|
||||
} disk;
|
||||
|
||||
|
||||
void get_disk()
|
||||
{
|
||||
CFMutableDictionaryRef match_dict = IOServiceMatching("IOMedia");
|
||||
if (!match_dict) {
|
||||
printf("failed to create match directory");
|
||||
}
|
||||
|
||||
CFDictionarySetValue(match_dict, CFSTR("Whole"), kCFBooleanTrue);
|
||||
|
||||
io_iterator_t iter;
|
||||
kern_return_t kr = IOServiceGetMatchingServices(kIOMainPortDefault, match_dict, &iter);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
printf("Error matching services");
|
||||
}
|
||||
|
||||
io_object_t service;
|
||||
while ((service = IOIteratorNext(iter))) {
|
||||
CFStringRef bsdName = IORegistryEntryCreateCFProperty(service, CFSTR("BSD Name"), kCFAllocatorDefault, 0);
|
||||
if (bsdName) {
|
||||
char name[1024];
|
||||
CFStringGetCString(bsdName, name, sizeof(name), kCFStringEncodingUTF8);
|
||||
printf("Disk: /dev/%s\n", name);
|
||||
CFRelease(bsdName);
|
||||
}
|
||||
|
||||
CFNumberRef sizeRef = IORegistryEntryCreateCFProperty(service, CFSTR("Size"), kCFAllocatorDefault, 0);
|
||||
if (sizeRef) {
|
||||
long long size = 0;
|
||||
CFNumberGetValue(sizeRef, kCFNumberLongLongType, &size);
|
||||
printf(" Size: %lld bytes\n", size);
|
||||
CFRelease(sizeRef);
|
||||
}
|
||||
|
||||
IOObjectRelease(service);
|
||||
}
|
||||
|
||||
IOObjectRelease(iter);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,145 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: ram.c
|
||||
*
|
||||
* Description: retrieve ram information from the device
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 04/08/2025 01:34:33
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: nasr
|
||||
* Organization: synf
|
||||
*
|
||||
* =====================================================================================*/
|
||||
|
||||
// OSX
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <math.h>
|
||||
|
||||
#define CONVERT_BYTES_TO_GIGABYTES 107374182
|
||||
|
||||
typedef struct {
|
||||
unsigned long mem_size;
|
||||
} ram;
|
||||
|
||||
unsigned long get_total(void);
|
||||
unsigned long get_usage(void);
|
||||
|
||||
|
||||
unsigned long get_usage(void)
|
||||
{
|
||||
|
||||
struct rusage usage;
|
||||
if(0 == getrusage(RUSAGE_SELF, &usage))
|
||||
return usage.ru_maxrss / CONVERT_BYTES_TO_GIGABYTES ;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long get_mem(void){
|
||||
|
||||
int mib[2];
|
||||
size_t size;
|
||||
uint64_t ram_size;
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_MEMSIZE;
|
||||
|
||||
size = sizeof(ram_size);
|
||||
if (sysctl(mib, 2, &ram_size, &size, NULL, 0) == -1) {
|
||||
perror("sysctl");
|
||||
}
|
||||
|
||||
return ram_size;
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("%lu", get_mem());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long mem_size;
|
||||
} ram;
|
||||
|
||||
unsigned long get_total(void);
|
||||
unsigned long get_usage(void);
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("compiled for __gnu_linux__");
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1], "total") == 0)
|
||||
{
|
||||
printf("Get the total ram usage");
|
||||
while (1) {
|
||||
|
||||
sleep(1);
|
||||
printf("%s", get_total());
|
||||
}
|
||||
}
|
||||
|
||||
else if (strcmp(argv[1], "name") == 0)
|
||||
{
|
||||
printf("Get the ram usage");
|
||||
printf("%lu", get_usage());
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("no arguments passed, try again with : frequency, temperature or name");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long get_total(void){
|
||||
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
return total_ram;
|
||||
|
||||
}
|
||||
|
||||
unsigned long get_usage(void)
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
long free_ram = info.freeram * info.mem_unit;
|
||||
|
||||
return total_ram - free_ram;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,49 +0,0 @@
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
float cpu_frequency(void);
|
||||
char* cpu_name(void);
|
||||
|
||||
float cpu_frequency(void)
|
||||
{
|
||||
uint64_t freq = 0;
|
||||
size_t size = sizeof(freq);
|
||||
|
||||
if (sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0) < 0)
|
||||
{
|
||||
perror("sysctl");
|
||||
}
|
||||
return freq;
|
||||
}
|
||||
|
||||
char* cpu_name(void){
|
||||
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("machdep.cpu.brand_string", NULL, &size, NULL, 0) < 0)
|
||||
perror("sysctl");
|
||||
|
||||
|
||||
char *name = malloc(size);
|
||||
|
||||
if(sysctlbyname("machdep.cpu.brand_string", &name, &size, NULL, 0) < 0){
|
||||
perror("sysctl");
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
float cpu_frequency(void);
|
||||
char* cpu_name(void);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -1,255 +0,0 @@
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <math.h>
|
||||
|
||||
#define MAXC 1024
|
||||
#define MAXC_CHAR 256
|
||||
|
||||
typedef struct {
|
||||
|
||||
int frequency;
|
||||
char* name;
|
||||
int threads;
|
||||
|
||||
} cpu_s;
|
||||
|
||||
typedef struct {
|
||||
|
||||
unsigned long mem_size;
|
||||
|
||||
} ram;
|
||||
|
||||
unsigned long get_total(void);
|
||||
unsigned long get_usage(void);
|
||||
long device_up_time(void);
|
||||
void name();
|
||||
void temperature();
|
||||
void freq();
|
||||
void *cpu_i(void *a);
|
||||
void *ram_i(void *a);
|
||||
void cpu_name(void);
|
||||
void cpu_temperature(unsigned short delay);
|
||||
char* cpu_frequency(void);
|
||||
|
||||
cpu_s _cpu;
|
||||
|
||||
void *cpu_name(){
|
||||
int buffer_size = 256;
|
||||
char cpu_name[buffer_size];
|
||||
|
||||
printf("Opening the CPU information files");
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp)
|
||||
printf("can't open /proc/cpuinfo");
|
||||
|
||||
char line[buffer_size];
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (strncmp(line, "model name", 10) == 0)
|
||||
{
|
||||
char *colon = strchr(line, ':');
|
||||
if (colon)
|
||||
{
|
||||
snprintf(cpu_name, buffer_size, "%s", colon + 2);
|
||||
cpu_name[strcspn(cpu_name, "\n")] = 0;
|
||||
int err = fclose(fp);
|
||||
if (err != 0)
|
||||
printf("error closing /proc/cpuinfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_cpu.name = cpu_name;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* cpu_frequency() {
|
||||
char* buffer = malloc(MAXC_CHAR);
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp) {
|
||||
printf("can't open /proc/cpuinfo");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(buffer, MAXC_CHAR, fp)) {
|
||||
if (strstr(buffer, "cpu MHz") != NULL)
|
||||
{
|
||||
char *colon = strchr(buffer, ':');
|
||||
if (colon)
|
||||
{
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
snprintf(buffer, MAXC_CHAR, "%s", colon);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *cpu_i(void *a){
|
||||
printf("thread is working");
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
unsigned long get_total(void){
|
||||
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
return total_ram;
|
||||
|
||||
}
|
||||
|
||||
unsigned long get_usage(void)
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
long free_ram = info.freeram * info.mem_unit;
|
||||
|
||||
return total_ram - free_ram;
|
||||
}
|
||||
|
||||
void *ram_i(void *a){
|
||||
|
||||
printf("thread is working");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cpu_name(void)
|
||||
{
|
||||
int buffer_size = 256;
|
||||
char cpu_name[buffer_size];
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp)
|
||||
printf("can't open /proc/cpuinfo");
|
||||
|
||||
char line[buffer_size];
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (strncmp(line, "model name", 10) == 0)
|
||||
{
|
||||
char *colon = strchr(line, ':');
|
||||
if (colon)
|
||||
{
|
||||
snprintf(cpu_name, buffer_size, "%s", colon + 2);
|
||||
cpu_name[strcspn(cpu_name, "\n")] = 0;
|
||||
int err = fclose(fp);
|
||||
if (err != 0)
|
||||
printf("error closing /proc/cpuinfo");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s", cpu_name);
|
||||
snprintf(cpu_name, buffer_size, "%s", cpu_name);
|
||||
}
|
||||
|
||||
void cpu_temperature(unsigned short delay)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
sleep(delay);
|
||||
FILE *pf = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
|
||||
if (!pf)
|
||||
printf("error reading /proc/cpuinfo");
|
||||
|
||||
char buffer[MAXC];
|
||||
while (fgets(buffer, sizeof(buffer), pf))
|
||||
{
|
||||
int a = atoi(buffer);
|
||||
a /= 1000;
|
||||
printf("%dC\n", a);
|
||||
fflush(stdout);
|
||||
}
|
||||
fclose(pf);
|
||||
}
|
||||
}
|
||||
|
||||
char* cpu_frequency(void) {
|
||||
char* buffer = malloc(MAXC_CHAR);
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp) {
|
||||
printf("can't open /proc/cpuinfo");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(buffer, MAXC_CHAR, fp)) {
|
||||
if (strstr(buffer, "cpu MHz") != NULL)
|
||||
{
|
||||
char *colon = strchr(buffer, ':');
|
||||
if (colon)
|
||||
{
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
snprintf(buffer, MAXC_CHAR, "%s", colon);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned long get_total(void){
|
||||
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
return total_ram;
|
||||
|
||||
}
|
||||
|
||||
unsigned long get_usage(void)
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
long free_ram = info.freeram * info.mem_unit;
|
||||
|
||||
return total_ram - free_ram;
|
||||
}
|
||||
|
||||
long device_up_time(void){
|
||||
struct sysinfo info;
|
||||
if (sysinfo(&info) == -1)
|
||||
perror("sysinfo");
|
||||
|
||||
return info.uptime;
|
||||
}
|
||||
|
||||
@ -1,173 +0,0 @@
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAXC 1024
|
||||
#define MAXC_CHAR 256
|
||||
|
||||
typedef struct {
|
||||
|
||||
int frequency;
|
||||
char* name;
|
||||
int threads;
|
||||
|
||||
} cpu_s;
|
||||
|
||||
void name();
|
||||
void temperature();
|
||||
void freq();
|
||||
void *cpu_i(void *a);
|
||||
|
||||
cpu_s _cpu;
|
||||
|
||||
void* cpu_name()
|
||||
{
|
||||
int buffer_size = 256;
|
||||
char cpu_name[buffer_size];
|
||||
|
||||
printf("Opening the CPU information files");
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp)
|
||||
printf("can't open /proc/cpuinfo");
|
||||
|
||||
char line[buffer_size];
|
||||
while (fgets(line, sizeof(line), fp))
|
||||
{
|
||||
if (strncmp(line, "model name", 10) == 0)
|
||||
{
|
||||
char *colon = strchr(line, ':');
|
||||
if (colon)
|
||||
{
|
||||
snprintf(cpu_name, buffer_size, "%s", colon + 2);
|
||||
cpu_name[strcspn(cpu_name, "\n")] = 0;
|
||||
int err = fclose(fp);
|
||||
if (err != 0)
|
||||
printf("error closing /proc/cpuinfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_cpu.name = cpu_name;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cpu_temperature(bool on, int delay){
|
||||
|
||||
while (1)
|
||||
{
|
||||
sleep(delay);
|
||||
FILE *pf = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
|
||||
if (!pf)
|
||||
printf("error reading /proc/cpuinfo");
|
||||
|
||||
char buffer[MAXC];
|
||||
while (fgets(buffer, sizeof(buffer), pf))
|
||||
{
|
||||
int a = atoi(buffer);
|
||||
a /= 1000;
|
||||
printf("%dC\n", a);
|
||||
fflush(stdout);
|
||||
}
|
||||
fclose(pf);
|
||||
}
|
||||
}
|
||||
|
||||
char* cpu_frequency() {
|
||||
char* buffer = malloc(MAXC_CHAR);
|
||||
|
||||
FILE *fp = fopen("/proc/cpuinfo", "r");
|
||||
if (!fp) {
|
||||
printf("can't open /proc/cpuinfo");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (fgets(buffer, MAXC_CHAR, fp)) {
|
||||
if (strstr(buffer, "cpu MHz") != NULL)
|
||||
{
|
||||
char *colon = strchr(buffer, ':');
|
||||
if (colon)
|
||||
{
|
||||
buffer[strcspn(buffer, "\n")] = 0;
|
||||
snprintf(buffer, MAXC_CHAR, "%s", colon);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return buffer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *cpu_i(void *a){
|
||||
printf("thread is working");
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef __gnu_linux__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long mem_size;
|
||||
} ram;
|
||||
|
||||
unsigned long get_total(void);
|
||||
unsigned long get_usage(void);
|
||||
void *ram_i(void *a);
|
||||
|
||||
|
||||
unsigned long get_total(void){
|
||||
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
return total_ram;
|
||||
|
||||
}
|
||||
|
||||
unsigned long get_usage(void)
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) != 0) {
|
||||
perror("sysinfo");
|
||||
return 1;
|
||||
}
|
||||
|
||||
long total_ram = info.totalram * info.mem_unit;
|
||||
long free_ram = info.freeram * info.mem_unit;
|
||||
|
||||
return total_ram - free_ram;
|
||||
}
|
||||
|
||||
void *ram_i(void *a){
|
||||
|
||||
printf("thread is working");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@ -1,80 +1,78 @@
|
||||
#include <pthread.h>
|
||||
#include "headers/cpu.h"
|
||||
#include "headers/ram.h"
|
||||
#include "headers/disk.h"
|
||||
#include "headers/device.h"
|
||||
#include <curl/curl.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <lib.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
cJSON convert_to_json(info info) {
|
||||
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(root, "cpu", info.cpu->name);
|
||||
cJSON_AddNumberToObject(root, "ram", info.ram->total);
|
||||
cJSON_AddStringToObject(root, "disk", info.disk->name);
|
||||
cJSON_AddStringToObject(root, "device", info.device->name);
|
||||
|
||||
return *root;
|
||||
}
|
||||
|
||||
void handler(char *url, cJSON object) {
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, object);
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, object);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||
curl_easy_strerror(res));
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||
curl_easy_strerror(res));
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
void setup_mt() {
|
||||
pthread_t cpu_t,ram_t; // disk_t , device_t;
|
||||
pthread_t cpu_t,ram_t; // disk_t , device_t;
|
||||
|
||||
pthread_create(&cpu_t, NULL, cpu_i, NULL);
|
||||
pthread_create(&ram_t, NULL, ram_i, NULL);
|
||||
// pthread_create(&disk_t, NULL, disk_i, NULL);
|
||||
// pthread_create(&device_t, NULL, device_i, NULL);
|
||||
pthread_create(&cpu_t, NULL, cpu_i, NULL);
|
||||
pthread_create(&ram_t, NULL, ram_i, NULL);
|
||||
// pthread_create(&disk_t, NULL, disk_i, NULL);
|
||||
// pthread_create(&device_t, NULL, device_i, NULL);
|
||||
|
||||
pthread_join(cpu_t, NULL);
|
||||
pthread_join(ram_t, NULL);
|
||||
// pthread_join(disk_t, NULL);
|
||||
// pthread_join(device_t, NULL);
|
||||
pthread_join(cpu_t, NULL);
|
||||
pthread_join(ram_t, NULL);
|
||||
// pthread_join(disk_t, NULL);
|
||||
// pthread_join(device_t, NULL);
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
setup_mt();
|
||||
handler("api.nsrddyn.com");
|
||||
setup_mt();
|
||||
handler("api.nsrddyn.com");
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __gnu_linux
|
||||
|
||||
void setup_mt(){
|
||||
|
||||
pthread_t cpu;
|
||||
pthread_t ram;
|
||||
pthread_t disk;
|
||||
pthread_t device;
|
||||
|
||||
pthread_create(&cpu, NULL, cpu_i, NULL);
|
||||
pthread_create(&ram, NULL, ram_i, NULL);
|
||||
pthread_create(&disk, NULL, disk_i, NULL);
|
||||
pthread_create(&device, NULL, device_i, NULL);
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
setup_mt();
|
||||
setup_mt();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
238
source/osx/lib.c
238
source/osx/lib.c
@ -1,238 +0,0 @@
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include "cpu.h"
|
||||
|
||||
void* cpu_name();
|
||||
void* cpu_thread_count();
|
||||
|
||||
cpu_s cpu;
|
||||
|
||||
void* cpu_name(){
|
||||
|
||||
char *name;
|
||||
size_t len = 0;
|
||||
|
||||
if (sysctlbyname("machdep.cpu.brand_string", NULL, &len, NULL, 0) < 0)
|
||||
perror("errorn in assigning the size for the cpu name variable\n");
|
||||
|
||||
name = malloc(len);
|
||||
|
||||
if(sysctlbyname("machdep.cpu.brand_string", name, &len, NULL, 0) < 0){
|
||||
perror("error in assigning the value to the cpu name variable\n");
|
||||
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cpu.name = name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* cpu_threads(){
|
||||
|
||||
int count;
|
||||
size_t len = sizeof(count);
|
||||
if (sysctlbyname("machdep.cpu.thread_count", &count, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the cpu threads count\n");
|
||||
|
||||
cpu.threads = count;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* cpu_info(){
|
||||
cpu_threads();
|
||||
cpu_name();
|
||||
|
||||
printf("cpu name: %s\ncpu threads: %d\n", cpu.name, cpu.threads);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <device.h>
|
||||
|
||||
device_s device_info;
|
||||
|
||||
void* device_name(){
|
||||
|
||||
char *name;
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("kern.hostname", NULL, &size, NULL, 0) < 0)
|
||||
perror("failed retrieving the hostname: \n");
|
||||
|
||||
name = malloc(size);
|
||||
|
||||
if(sysctlbyname("kern.hostname", name, &size, NULL, 0) < 0){
|
||||
perror("failed retrieving the hostname: \n");
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device_info.name = name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void* device_model(){
|
||||
|
||||
char *model_name;
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("hw.model", NULL, &size, NULL, 0) < 0)
|
||||
perror("failed retrieving the hostname: \n");
|
||||
|
||||
model_name = malloc(size);
|
||||
|
||||
if(sysctlbyname("hw.model", model_name, &size, NULL, 0) < 0){
|
||||
perror("failed retrieving the hostname: \n");
|
||||
free(model_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device_info.model = model_name;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void* device_up_time(){
|
||||
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* device_os_version(){
|
||||
|
||||
char *os_version;
|
||||
size_t size = 0;
|
||||
|
||||
if (sysctlbyname("kern.ostype", NULL, &size, NULL, 0) < 0)
|
||||
perror("failed retrieving the hostname: \n");
|
||||
|
||||
os_version = malloc(size);
|
||||
|
||||
if(sysctlbyname("kern.ostype", os_version, &size, NULL, 0) < 0){
|
||||
perror("failed retrieving the os version: \n");
|
||||
free(os_version);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device_info.model = os_version;
|
||||
return NULL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void* get_device_info(){
|
||||
device_name();
|
||||
device_model();
|
||||
printf("device name: %s\ndevice model: %s\n", device_info.name, device_info.model);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "modules/cpu.h"
|
||||
#include "modules/ram.h"
|
||||
#include "modules/disk.h"
|
||||
#include "modules/device.h"
|
||||
#include <cjson/cJSON.h>
|
||||
|
||||
typedef struct {
|
||||
|
||||
cpu_s* cpu;
|
||||
ram_s* ram;
|
||||
disk_s* disk;
|
||||
device_s* device;
|
||||
|
||||
} info;
|
||||
|
||||
|
||||
cJSON convert_to_json(info info){
|
||||
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(root, "cpu", info.cpu->name);
|
||||
cJSON_AddNumberToObject(root, "ram", info.ram->total);
|
||||
cJSON_AddStringToObject(root, "disk", info.disk->name);
|
||||
cJSON_AddStringToObject(root, "device", info.device->name);
|
||||
|
||||
return *root;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include "ram.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
void size();
|
||||
void av_size();
|
||||
void* ram_i();
|
||||
|
||||
|
||||
ram_s data;
|
||||
|
||||
#define D 1073741824
|
||||
|
||||
|
||||
void size() {
|
||||
int64_t size;
|
||||
size_t len = sizeof(size);
|
||||
if (sysctlbyname("hw.memsize", &size, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the memory size");
|
||||
|
||||
data.total = size / D;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void av_size() {
|
||||
int64_t size;
|
||||
size_t len = sizeof(size);
|
||||
if (sysctlbyname("hw.memsize_usable", &size, &len, NULL, 0) < 0)
|
||||
perror("error in retrieving the available memory size");
|
||||
|
||||
data.available = size / D;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ram_info() {
|
||||
size();
|
||||
av_size();
|
||||
|
||||
printf("available ram: %LF\n", data.available);
|
||||
printf("total ram: %LF\n", data.total);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* ram_i(){
|
||||
|
||||
printf("thread is working");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user