linux下system函数头文件,Linux C:system函数与后台作业

system函数的参数(字符串)是要执行的命令,这个命令可以使用 & 运行后台作业,也可以一次执行多个程序。

示例1:

#include

int

main()

{

int status;

if ( (status = system("ping baidu.com -c 3")) < 0) {

printf("error occured\n");

}

printf("after???\n");

return 0;

}

运行结果:

PING baidu.com (180.149.132.47) 56(84) bytes of data.

64 bytes from 180.149.132.47: icmp_seq=1 ttl=48 time=365 ms

64 bytes from 180.149.132.47: icmp_seq=2 ttl=48 time=357 ms

64 bytes from 180.149.132.47: icmp_seq=3 ttl=48 time=372 ms

--- baidu.com ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2001ms

rtt min/avg/max/mdev = 357.866/365.516/372.928/6.151 ms

after???

示例2:后台作业

#include

int

main()

{

int status;

if ( (status = system("ping baidu.com -c 3 &")) < 0) {

printf("error occured\n");

}

printf("after???\n");

return 0;

}

运行结果:

after???

PING baidu.com (180.149.132.47) 56(84) bytes of data.

╭─ ~/Desktop/test

╰─➤ 64 bytes from 180.149.132.47: icmp_seq=1 ttl=48 time=351 ms

64 bytes from 180.149.132.47: icmp_seq=2 ttl=48 time=359 ms

64 bytes from 180.149.132.47: icmp_seq=3 ttl=48 time=347 ms

--- baidu.com ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2002ms

rtt min/avg/max/mdev = 347.331/352.922/359.501/5.040 ms

示例3:一次执行多个命令

#include

int

main()

{

int status;

if ( (status = system("date; ping baidu.com -c 3")) < 0) {

printf("error occured\n");

}

printf("after???\n");

return 0;

}

运行结果:

Fri Mar 18 22:18:58 CST 2016

PING baidu.com (123.125.114.144) 56(84) bytes of data.

64 bytes from 123.125.114.144: icmp_seq=1 ttl=48 time=326 ms

64 bytes from 123.125.114.144: icmp_seq=2 ttl=48 time=320 ms

64 bytes from 123.125.114.144: icmp_seq=3 ttl=48 time=325 ms

--- baidu.com ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2002ms

rtt min/avg/max/mdev = 320.754/324.180/326.318/2.534 ms

after???

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值