首页 \ 问答 \ Linux 这个系统的英文发音 怎样读?中文名字叫什么?

Linux 这个系统的英文发音 怎样读?中文名字叫什么?

更新时间:2022-07-15 06:07

最满意答案

可以通过system函数,调用shell命令。
1 函数原型:
int system(const char *cmd);
2 功能:
调用cmd内容的系统命令,即shell命令。
3 头文件:
stdlib.h
4 举例:
system("ls");
打印当前工作目录下的文件。

其他回答

在c语言中调用shell命令的方法实现。
c程序调用shell脚本共有两种方法 :system()、popen(),分别如下:
system() 
不用自己去创建进程,系统已经封装了这一步,直接加入自己的命令即可
popen() 也可以实现执行的命令,比system 
开销小
以下分别说明:
1)system(shell命令或shell脚本路径);
   system() 
会调用fork()产生 子历程,由子历程来调用/bin/sh-c string来履行 参数string字符串所代表的命令,此命令履行 
完后随即返回原调用的历程。在调用system()期间sigchld 信号会被暂时搁置,sigint和sigquit 信号则会被漠视 。
    返 
回值:如果system()在调用/bin/sh时失败则返回127,其他失败原因返回-1。若参数string为空指针(null),则返回非零值。 如果 
system()调用成功 则最后会返回履行 shell命令后的返回值,但是此返回值也有可能为system()调用/bin/sh失败所返回的127,因 
此最好能再反省 errno 来确认履行 成功 。
   system命令以其简略 
高效的作用得到很很广泛 的利用 ,下面是一个例子
例:在/tmp/testdir/目录下有shell脚本tsh.sh,内容为

#!/bin/sh
wget $1
echo "done!"
2)popen(char 
*command,char *type)   
    popen() 
会调用fork()产生 子历程,然后从子历程中调用/bin/sh -c来履行 参数command的指令。参数type可应用 
“r”代表读取,“w”代表写入。遵循此type值,popen()会建立 管道连到子历程的标准 输出设备 或标准 输入设备 
,然后返回一个文件指针。随后历程便可利用 此文件指针来读取子历程的输出设备 或是写入到子历程的标准 输入设备 中。此外,所有应用 文 
件指针(file*)操作的函数也都可以应用 ,除了fclose()以外。
    返回值:若成功 
则返回文件指针,否则返回null,差错 原因存于errno中。注意:在编写具suid/sgid权限的程序时请尽量避免应用 
popen(),popen()会继承环境变量,通过环境变量可能会造成系统安全的问题。
例:c程序popentest.c内容如下:
 #include

 
    main
    {
        file * fp;
        charbuffer[80];
        fp=popen(“~/myprogram/test.sh”,”r”);
        fgets(buffer,sizeof(buffer),fp);
        printf(“%s”,buffer);
        pclose(fp);
    }
system 这个函数可以帮到你。 参数就一个 就是shell命令
1、可以使用system函数调用。system("shell_command");可以实现在shell中调用shell_command的作用。
2、例如设置网卡IP为192.168.1.100,可以写作
system("ifconfig eth0 192.168.1.100");
题主可以使用 exec 系列函数。这系列函数定义在 unistd.h 头文件中,所以使用前请包含这个头文件。这系列函数共有五个,
execl, execlp, execv, execvp, execle其中常用的是前四个。前四个函数的原型为:
int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);这四个函数的主要差别就在于参数的类型和用不用输入命令的绝对路径上。
以路径形式来分,凡是函数名中带 p 的(execlp,execvp)都只需要提供命令的名,函数会自动在当前的环境变量 $PATH 中查找命令的路径。而不带 p 的(execl,execv)必须要提供命令的绝对路径,否则函数会找不到这个命令的位置。这里以 execl 和 execlp 为例,以下运行
ls -l命令的代码:


#include 

 
#include 
 
  

int main() {

    // exec 系列函数出错时会返回 -1,平常返回 0,所以可以
    // 据此来打印错误信息
    // 第一个 ls 是命令的名称,execlp 函数会自动在 $PATH
    // 中寻找这个命令。
    // 后面一个 ls 是要在 shell 中输入的第一个参数
    //(也就是命令名称本身)
    // 使用 NULL 作为参数结尾标记是 exec 系列函数的要求。
    if (execlp("ls", "ls", "-l", NULL) == -1)
        perror("Error Executing Command.\n");
    return 0;

}在 shell 中运行这个 C 程序会输出







和你直接在 shell 中写 ls -l 的效果是一样的。然而,如果你使用不带 p 的 execl, 那么这样写就会报错。


#include 
  
   
#include 
   
    

int main() {

    // execl 只接受命令的绝对路径,所以必须输入完整的
    // 路径 /bin/ls,即
    // if (execl("/bin/ls", "ls", "-l", NULL) == -1)
    if (execl("ls", "ls", "-l", NULL) == -1)
        perror("Error Executing Command.\n");
    return 0;

}输出结果为:







以参数类型来分,凡是函数名中带 l 的(execl,execlp)都需要把系统命令的参数全部传递给函数,而凡是函数名中带 v 的(execv,execvp)都需要把系统命令的参数统一放在一个数组里,然后把这个数组传递给函数。


比如刚才这个


#include 
    
     
#include 
     
       int main() {     if (execlp("ls", "ls", "-l", NULL) == -1)         perror("Error Executing Command.\n");     return 0; } 如果改用 execvp 来写的话就是 #include 
      
        #include 
       
         int main() {     // 这个字符串数组存有所有参数(包括命令名本身和     // 最后的 NULL)     char * argv[] = {"ls", "-l", NULL};     // 这里只需将命令名称和参数数组传递给 execvp 函数即可,     // 无需将参数一个个传递。同样函数会自动在 $PATH      // 中查找命令     if (execvp("ls", argv) == -1)         perror("Error Executing Command.\n");     return 0; } 运行结果同样和直接写 ls -l 的效果相同。 execv 和 execvp 的区别也在于是否必须输入绝对路径,就不赘述了。 要注意的一点是,如果执行成功,exec 系列函数开启的新进程会完全代替当前的进程,也就是说当前进程会消失。所以一般会将 exec 和 fork 连用,先 fork 出一个子进程,然后在这个子进程中使用 exec 运行别的程序,防止父进程被 exec 覆盖。比如刚才的代码稍微改一下 #include 
        
          #include 
         
           int main() {     char * argv[] = {"ls", "-l", NULL};     if (execvp("ls", argv) == -1)         perror("Error Executing Command.\n");     // 加入一个 printf 语句     printf("Main process is still running.\n");     return 0; } 运行后并不会出现 Main process is still running 这句话,因为 exec 后 main 函数执行产生的进程已经被 ls 命令产生的进程完全覆盖了,所以 exec 函数以下的语句是完全不会执行的。这时就可以使用 fork 来新建一个子进程,在子进程中执行 exec 函数。 #include 
          
            #include 
           
             #include 
            
              #include 
             
               int main() {     int r;     // fork() 大于零,父进程     if ((r = fork()) > 0) {         int status;         if (wait(&status) != -1) {             // 等待子进程退出             if(WIFEXITED(status)) {                 printf("Main process is still running.\n");                 return 0;             }         }     // fork () 等于零,子进程。子进程中运行 exec         } else if (r == 0) {         char * argv[] = {"ls", "-l", NULL};         if (execvp("ls", argv) == -1)             perror("Error Executing Command.\n");         return 0;     // fork() 小于零,出错     } else {         perror("Fork");     }     return 0; }这样运行结果就变成了  Main process is still running 这句话就会被输出到屏幕上。
             
            
           
          
         
        
       
      
     
    
   
  
 

相关问答

更多
  • C语言中的线程?[2022-10-31]

    给你推荐一些比较好的教程吧,你应该用得着: 漫谈C++ Builder多线程编程技术: http://www.it55.com/html/xueyuan/chengxukaifa/Visual_C__jiaocheng/20070626/7625.html 用MFC编写多线程程序实例: http://www.it55.com/html/xueyuan/chengxukaifa/Visual_C__jiaocheng/20070626/7647.html C++写的web服务器程序(多线程): http:// ...
  • 只要以%c格式符输出该ASCII码值,就可以了。 int x=65; printf("%c",x); 就可以输出一个A。
  • 程序设计中的函数 许多程序设计语言中,可以将一段经常需要使用的代码封装起来,在需要使用时可以直接调用,这就是程序中的函数。比如在C语言中: int max(int x,int y) { return(x>y?x:y;); } 就是一段比较两数大小的函数,函数有参数与返回值。C++程序设计中的函数可以分为两类:带参数的函数和不带参数的函数。这两种参数的声明、定义也不一样。 带有(一个)参数的函数的声明: 类型名标示符+函数名+(类型标示符+参数) { } 不带参数的函数的声明: void+函数名() { } ...
  • 这种提示一般是你代码中的 指针指向了系统内存的只读地址,并且你的代码里有尝试修改这个值的操作,这样操作系统当然不允许你修改,就会提示上面的错误。 具体要看代码了,最好还是把代码贴上来,这种错误不是语法错误。。。语法错误编译器会报错的。
  • EOF一般作为文件的结尾标记。其值是-1,也就是说在 如下定义 #define EOF -1 -1对应着ctrl+Z,在有些系统也对应着f6键。 文件的结尾都有EOF,因此可以用如下程序显示一个文件的内容: char c; FILE *fp; fp = fopen("filename.txt", "rt"); while((c=fgetc(fp)!=EOF)putchar(c); 也可以如下写: while((c=fgetc(fp)!=-1)putchar(c); .
  • 直接对二进制数的运算、
  • 随手写的一段小程序,可以参考一下 #include #include main(argc,argv) int argc; char *argv[]; { FILE * fileHandle; char a[4] = "abc"; if(argc != 2){ printf("%s fileName\n",argv[0]); exit(-1); } if((fileHandle = fopen(argv[1], "wb")) == NULL){ printf("%s open error\n", argv[1 ...
  • 在C语言中调用shell命令的方法实现。 C程序调用shell脚本共有两种方法 :system()、popen(),分别如下: system() 不用自己去创建进程,系统已经封装了这一步,直接加入自己的命令即可 popen() 也可以实现执行的命令,比system 开销小 以下分别说明: 1)system(shell命令或shell脚本路径); system() 会调用fork()产生 子历程,由子历程来调用/bin/sh-c string来履行 参数string字符串所代表的命令,此命令履行 完后随即返回 ...
  • 可以通过system函数,调用shell命令。 1 函数原型: int system(const char *cmd); 2 功能: 调用cmd内容的系统命令,即shell命令。 3 头文件: stdlib.h 4 举例: system("ls"); 打印当前工作目录下的文件。
  • 1,shell命令不是c语言——尽管shell本身和你输入的命令(如ls)绝大多数都是c语言完成的。单个shell命令也算不上脚本语言,硬要算的话,勉强算单行的脚本语言吧。 2,脚本语言都是纯文本格式,解释器(一个可执行程序)读取它,解释并执行其中的代码。多个shell命令可以组合起来,形成shell脚本,由shell负责解释执行。shell脚本具有函数,控制结构等编程语言的基本要素,因此写shell脚本也算一种编程,但是相对更简单。 3,shell脚本一般是利用系统里现有的可执行程序,组合起来完成一些任务 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)