zoukankan      html  css  js  c++  java
  • leetcode 服务器环境

    今天因为好奇扒取了 leetcode 服务器端的开发环境。


    • 方法:随便找个题,利用stdout 输出系统信息,如下:

    • 完整信息如下:
      === os information ===
      Linux version 4.4.0-131-generic (buildd@lgw01-amd64-015) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) ) #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018
      === cpu infomation ===
      processor : 0
      vendor_id : GenuineIntel
      cpu family : 6
      model : 79
      model name : Intel(R) Xeon(R) CPU E5-2697A v4 @ 2.60GHz
      stepping : 1
      microcode : 0x1
      cpu MHz : 2599.996
      cache size : 40960 KB
      physical id : 0
      siblings : 1
      core id : 0
      cpu cores : 1
      apicid : 0
      initial apicid : 0
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single kaiser tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt
      bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass
      bogomips : 5199.99
      clflush size : 64
      cache_alignment : 64
      address sizes : 40 bits physical, 48 bits virtual
      power management:
      processor : 1
      vendor_id : GenuineIntel
      cpu family : 6
      model : 79
      model name : Intel(R) Xeon(R) CPU E5-2697A v4 @ 2.60GHz
      stepping : 1
      microcode : 0x1
      cpu MHz : 2599.996
      cache size : 40960 KB
      physical id : 1
      siblings : 1
      core id : 0
      cpu cores : 1
      apicid : 1
      initial apicid : 1
      fpu : yes
      fpu_exception : yes
      cpuid level : 13
      wp : yes
      flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single kaiser tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt
      bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass
      bogomips : 5199.99
      clflush size : 64
      cache_alignment : 64
      address sizes : 40 bits physical, 48 bits virtual
      power management:
      === memory information ===
      MemTotal: 4046404 kB
      MemFree: 1329068 kB
      MemAvailable: 1974100 kB
      Buffers: 159648 kB
      Cached: 597080 kB
      SwapCached: 29884 kB
      Active: 1286924 kB
      Inactive: 602876 kB
      Active(anon): 657084 kB
      Inactive(anon): 515256 kB
      Active(file): 629840 kB
      Inactive(file): 87620 kB
      Unevictable: 3652 kB
      Mlocked: 3652 kB
      SwapTotal: 524284 kB
      SwapFree: 3020 kB
      Dirty: 12 kB
      Writeback: 0 kB
      AnonPages: 1107024 kB
      Mapped: 44892 kB
      Shmem: 36728 kB
      Slab: 720068 kB
      SReclaimable: 215152 kB
      SUnreclaim: 504916 kB
      KernelStack: 4848 kB
      PageTables: 9472 kB
      NFS_Unstable: 0 kB
      Bounce: 0 kB
      WritebackTmp: 0 kB
      CommitLimit: 2547484 kB
      Committed_AS: 2099816 kB
      VmallocTotal: 34359738367 kB
      VmallocUsed: 0 kB
      VmallocChunk: 0 kB
      HardwareCorrupted: 0 kB
      AnonHugePages: 0 kB
      CmaTotal: 0 kB
      CmaFree: 0 kB
      HugePages_Total: 0
      HugePages_Free: 0
      HugePages_Rsvd: 0
      HugePages_Surp: 0
      Hugepagesize: 2048 kB
      DirectMap4k: 3686380 kB
      DirectMap2M: 507904 kB
      DirectMap1G: 0 kB

    • 源代码(获取系统信息的代码参考了):

    
    #include <stdio.h>
    
    #include <stdlib.h>
    
    #include <string.h>
    
     
    
    // mostly need to read the linux config files to get system info
    
     
    
    // ---- get os info ---- //
    
    void getOsInfo()
    
    {
    
        FILE *fp = fopen("/proc/version", "r");
    
        if(NULL == fp)
    
            printf("failed to open version
    ");
    
        char szTest[1000] = {0};
    
        while(!feof(fp))
    
        {
    
            memset(szTest, 0, sizeof(szTest));
    
            fgets(szTest, sizeof(szTest) - 1, fp); // leave out 
    
    
            printf("%s", szTest);
    
        }
    
        fclose(fp);
    
    }
    // ---- get cpu info ---- //
    
    void getCpuInfo()
    
    {
    
        FILE *fp = fopen("/proc/cpuinfo", "r");
    
        if(NULL == fp)
    
            printf("failed to open cpuinfo
    ");
    
        char szTest[1000] = {0};
    
        // read file line by line
    
        while(!feof(fp))
    
        {
    
            memset(szTest, 0, sizeof(szTest));
    
            fgets(szTest, sizeof(szTest) - 1, fp); // leave out 
    
    
            printf("%s", szTest);
    
        }
    
        fclose(fp);
    
    }
    
     
    
     
    
    // ---- get memory info ---- //
    
    void getMemoryInfo()
    
    {
    
        FILE *fp = fopen("/proc/meminfo", "r");
    
        if(NULL == fp)
    
            printf("failed to open meminfo
    ");
    
        char szTest[1000] = {0};
    
        while(!feof(fp))
    
        {
    
            memset(szTest, 0, sizeof(szTest));
    
            fgets(szTest, sizeof(szTest) - 1, fp);
    
            printf("%s", szTest);
    
        }
    
        fclose(fp);
    
    }
    
     
    
    // ---- get harddisk info ---- //
    
    #include <fcntl.h>
    
    #include <sys/ioctl.h>
    
    #include <linux/hdreg.h>
    
     
     
     
    
    void lin()
    
    {
    
        printf("=== os information ===
    ");
    
        getOsInfo();
        
        printf("=== cpu infomation ===
    ");
    
        getCpuInfo();
    
     
    
        printf("=== memory information ===
    ");
    
        getMemoryInfo();
    
    }
    
    class Solution {
    public:
        vector<vector<int>> threeSum(vector<int>& nums) {
            lin();//选哪个题无所谓,调用一遍lin()就行,此处是选的3Sum这题
            vector<vector<int>> t;
            return t;
        }
    };
    
  • 相关阅读:
    147-SpirngBoot指定编译那个文件的xml文件?
    146-springboot打war包设置
    145-sprinboot导入的内嵌jsp依赖是什么?
    mybatis中映射文件和实体类的关联性
    Quartz使用-入门使用(java定时任务实现)
    java SSLContext
    方法参数传递
    JSP写的图书管理系统
    JAVA---数组
    SpringBoot 2.x 后WebMvcConfigurationAdapter 过时
  • 原文地址:https://www.cnblogs.com/yhjd/p/10647203.html
Copyright © 2011-2022 走看看