小弟我用C写了一个程序在Linux系统执行,如何样才能提高效率
发布时间:2011-06-28 16:17:10 文章来源:www.iduyao.cn 采编人员:星星草
我用C写了一个程序在Linux系统执行,怎么样才能提高效率?
执行getCommand 函数获得命令,如果命令正确就发出去,如果没发送成功就每隔一段时间再发过去。如果发送成功,则每隔一段时间重新获得新的command命令,和上次的进行比较,如果不相同就再发过去。
怎么样提高效率??
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <linux/sockios.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <unistd.h>
/*
* 把字符串中的所有字符转换成小写字母
*/
void getLower(char *upper)
{
int i;
for(i = 0; upper[i] != '\0'; i++)
upper[i] = tolower(upper[i]);
}
int getCommand(char *comm)
{
//获得 comm,成功返回 1 ,else 返回 0
}
int main()
{
char command[150] = "";
char temp[150] = "";
int flag = 1, result = 0;
while(1)
{
result = getCommand(command);
printf("%s\n", command);
if(result == 1)
{
if(flag == 0)
{
if(strcmp(temp, command) != 0)
{
flag = system(command);
if(flag == 0)
strcpy(temp, command);
}
}
else
{
flag = system(command);
if(flag == 0)
strcpy(temp, command);
}
}
sleep(60);
}
return 0;
}
------解决方案--------------------
提高什么的效率,代码执行效率还是说命令发送的效率?
------解决方案--------------------
推敲下
------解决方案--------------------
一条命令发送不成功最多三次,放弃重新发送本条命令。
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
【★C/C++奖励基金-30期★】更新获奖书籍,请选择~ - C/C++ / 非技术区
【★C/C++奖励基金-30期★】
C/C++ 2011-12专家榜
名次...
-
C/c++ 如何按位拷贝呢?
我有一个结构体
strut st_header
{
unsigned short ver:2
unsigned short ping:1
unsgne...
-
uboot上的一点代码,没看明白!
struct in_str {
const char *p;
#ifndef __U_BOOT__
char peek_buf[2];
#endif
int __promptme;
...
-
Debug时为什么变量的地址不变?
是巧合还是某种必然. 是不是因为C中生成的可执行程序存储的地址是相对地址而不是绝对的物理地址.
...
-
关于switch语句。我不知道哪里错了,大侠帮忙bug一下
#include <stdio.h>
int main()
{
int a;
char b;
do{
printf("1.Chines...
-
#pragma section 的 $ 语法
在 ARX 头文件中间过如下三行,放在一起:
#pragma section("ARXCOMMAND$__a")
#pragma section("ARXCOMM...
-
read 问题再现
#define N 205
signed short x[N];
for(i=0;i<N;i++)
{
printf("hello boy!!\n");
...
-
征求一个C语言输入函数?
不知道大家有没有学习过Java? 现在需要一个类似Java的Scanner的函数集, 要求如下:
1. 三个函数: int rea...
-
求一道算法。一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
/*我写了一点,但是有错误,汗*/
/*
...
-
3n+1问题
求救,不知道错在哪里
#include<stdio.h>
int count(int a,int b)
{
int max=0,len=0,a1;
while(a<=b)
{
...