system()函数功能简述

原文链接:linux system函数详解 - 南哥的天下 - 博客园

system()函数的返回值如下: 成功,则返回进程的状态值; 当sh不能执行时,返回127; 失败返回-1;

在前面写exec族函数文章中得代码示例中稍作修改如下:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
        // int system(const char *command);
        printf("before system\n");

        if(system("ps -l") == -1){
                printf("system failed!\n");
                perror("why");
         }
        printf("after system\n");

        return 0;
}

运行结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
常用的手机硬件设备信息包括: 1. 手机型号:手机的型号名称,例如iPhone X、Samsung Galaxy S10等; 2. 操作系统版本:手机所使用的操作系统版本,例如iOS 14、Android 10等; 3. CPU型号和频率:手机的处理器型号和主频,例如Qualcomm Snapdragon 855、Apple A13 Bionic等; 4. 内存大小:手机的内存容量,例如6GB、8GB等; 5. 存储容量:手机的存储空间大小,例如64GB、128GB等; 6. 屏幕分辨率:手机屏幕的分辨率,例如1920x1080、2436x1125等; 7. 相机像素:手机的摄像头像素数,例如1200万像素、4000万像素等; 8. 电池容量:手机的电池容量,例如3000mAh、4000mAh等。 获取这些信息的方法函数在不同的操作系统和编程语言中可能略有不同。在Android系统中,可以使用android.os.Build类中的各种属性获取硬件信息,例如: ``` String model = Build.MODEL; // 手机型号 String osVersion = Build.VERSION.RELEASE; // 操作系统版本 String cpuModel = Build.HARDWARE; // CPU型号 long totalMemory = Runtime.getRuntime().totalMemory(); // 内存总大小 long freeMemory = Runtime.getRuntime().freeMemory(); // 内存可用大小 File path = Environment.getDataDirectory(); // 存储路径 long totalSpace = path.getTotalSpace(); // 存储总大小 long freeSpace = path.getFreeSpace(); // 存储可用大小 DisplayMetrics dm = getResources().getDisplayMetrics(); // 获取屏幕分辨率 int screenWidth = dm.widthPixels; int screenHeight = dm.heightPixels; ``` 在iOS系统中,可以使用UIDevice类和NSProcessInfo类中的各种属性获取硬件信息,例如: ``` NSString *model = [[UIDevice currentDevice] model]; // 手机型号 NSString *osVersion = [[UIDevice currentDevice] systemVersion]; // 操作系统版本 NSString *cpuModel = [[NSProcessInfo processInfo] processorDescription]; // CPU型号 NSUInteger totalMemory = [NSProcessInfo processInfo].physicalMemory; // 内存总大小 NSUInteger freeMemory = [NSProcessInfo processInfo].availablePhysicalMemory; // 内存可用大小 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [paths objectAtIndex:0]; // 存储路径 NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error:nil]; NSNumber *totalSpace = [fileAttributes objectForKey:NSFileSystemSize]; // 存储总大小 NSNumber *freeSpace = [fileAttributes objectForKey:NSFileSystemFreeSize]; // 存储可用大小 CGSize screenSize = [UIScreen mainScreen].bounds.size; // 获取屏幕分辨率 CGFloat screenWidth = screenSize.width; CGFloat screenHeight = screenSize.height; ``` 需要注意的是,某些硬件信息可能需要特殊的权限才能获取,例如相机像素、电池容量等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值