当前位置:首页 » 操作系统 » linux函数定义

linux函数定义

发布时间: 2022-05-11 00:23:25

linux信号处理函数定义,看不懂,请大师们帮忙

P((void))应该是个宏,并且是个函数指针,举例 deifine P((Y)) (Y y) 其中Y为传递的参数类型

static void failure P((void)) = static void failure (void) ,是一个函数名

static void failure P((void))一样的

void qsignal(sig,action)const int sig;void(*action)P((void));//定义函数qsignal,但是我感觉应该没这种用法把,应该写成void qsignal(const int sig,void(*action)P((void)));当然了要看你的编译器了,如果你是用的什么单片机的编译器,也有可能有这种写法,其实就是

申明了函数原型,在说明形参的类型 我记得貌似早起的c语言89版有这个写法的
qsignal(SIGINT,failure); 貌似应该是qsignal(SIGINT,&failure);

你看看还有什么不明白的

Ⅱ linux怎么读区间函数

系统环境:ubuntu10.04

简介
本文旨在为了解Linux各种时间类型与时间函数提供技术文档。

1、Linux下常用时间类型
Linux下常用时间类型有四种:time_t、structtm、structtimeval、structtimespec

1.1time_t时间类型
time_t类型在time.h中定义:

[cpp]view plain

  • #ifndef__TIME_T

  • #define__TIME_T

  • typedeflongtime_t;

  • #endif

  • 可见,time_t实际是一个长整型。其值表示为从UTC(coordinateniversaltime)时间1970年1月1日00时00分00秒(也称为Linux系统的Epoch时间)到当前时刻的秒数。由于time_t类型长度的限制,它所表示的时间不能晚于2038年1月19日03时14分07秒(UTC)。为了能够表示更久远的时间,可用64位或更长的整形数来保存日历时间,这里不作详述。
    使用time()函数获取当前时间的time_t值,使用ctime()函数将time_t转为当地时间字符串。
    备注:UTC时间有时也称为GMT时间,其实UTC和GMT两者几乎是同一概念。它们都是指格林尼治标准时间,只不过UTC的称呼更为正式一点。两者区别在于前者是天文上的概念,而后者是基于一个原子钟。

    1.2structtm时间类型
    tm结构在time.h中定义:

    [cpp]view plain

  • #ifndef_TM_DEFINED

  • structtm{

  • inttm_sec;/*秒-取值区间为[0,59]*/

  • inttm_min;/*分-取值区间为[0,59]*/

  • inttm_hour;/*时-取值区间为[0,23]*/

  • inttm_mday;/*日-取值区间为[1,31]*/

  • inttm_mon;/*月份-取值区间为[0,11]*/

  • inttm_year;/*年份-其值为1900年至今年数*/

  • inttm_wday;/*星期-取值区间[0,6],0代表星期天,1代表星期1,以此类推*/

  • inttm_yday;/*从每年的1月1日开始的天数-取值区间为[0,365],0代表1月1日*/

  • inttm_isdst;/*夏令时标识符,使用夏令时,tm_isdst为正,不使用夏令时,tm_isdst为0,不了解情况时,tm_isdst为负*/

  • };

  • #define_TM_DEFINED

  • #endif

  • ANSIC标准称使用tm结构的这种时间表示为分解时间(broken-downtime)。
    使用gmtime()和localtime()可将time_t时间类型转换为tm结构体;
    使用mktime()将tm结构体转换为time_t时间类型;
    使用asctime()将structtm转换为字符串形式。

    1.3structtimeval时间类型
    timeval结构体在time.h中定义:

    [cpp]view plain

  • Structtmieval{

  • time_ttv_sec;/*秒s*/

  • suseconds_ttv_usec;/*微秒us*/

  • };

  • 设置时间函数settimeofday()与获取时间函数gettimeofday()均使用该事件类型作为传参。

    1.4structtimespec时间类型
    timespec结构体在time.h定义:

    [cpp]view plain

  • structtimespec{

  • time_ttv_sec;/*秒s*/

  • longtv_nsec;/*纳秒ns*/

  • };


  • 2、Linux下常用时间函数
    Linux下常用时间函数有:time()、ctime()、gmtime()、localtime()、mktime()、asctime()、difftime()、gettimeofday()、settimeofday()

    2.1time()函数
    头文件:#include<time.h>
    函数定义:time_ttime(time_t*timer)
    功能描述:该函数返回从1970年1月1日00时00分00秒至今所经过的秒数。如果time_t*timer非空指针,函数也会将返回值存到timer指针指向的内存。
    返回值:成功则返回秒数,失败则返回((time_t)-1)值,错误原因存于errno中。
    例:

    [cpp]view plain

  • time_tseconds;

  • seconds=time((time_t*)NULL);


  • 2.2ctime()函数
    头文件:#include<time.h>
    函数定义:char*ctime(consttime_t*timep);
    功能描述:ctime()将参数timep指向的time_t时间信息转换成实际所使用的时间日期表示方法,并以字符串形式返回。字符串格式为:"WedJun2021:00:002012 "。
    例:

    [cpp]view plain

  • time_ttimep;

  • tmep=time(NULL);

  • printf("%s ",ctime(&timep));


  • 2.3gmtime()函数
    头文件:#include<time.h>
    函数定义:structtm*gmtime(consttime_t*timep)
    功能描述:gmtime()将参数timep指向的time_t时间信息转换成以tm结构体表示的GMT时间信息,并以structtm*指针返回。
    GMT:GMT是中央时区,北京在东8区,相差8个小时,所以北京时间=GMT时间+8小时。
    例:

    [cpp]view plain

  • intmain(void)

  • {

  • char*wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

  • time_ttimep;

  • structtm*p_tm;

  • timep=time(NULL);

  • p_tm=gmtime(&timep);/*获取GMT时间*/

  • printf("%d-%d-%d",(p_tm->tm_year+1900),(p_tm->mon+1),p_tm->tm_mday);

  • printf("%s%d:%d:%d ",wday[p_tm->tm_wday],p_tm->tm_hour,p_tm->tm_min,p_tm->tm_sec);

  • }


  • 2.4localtime()函数
    头文件:#include<time.h>
    函数定义:structtm*localtime(consttime_t*timep);
    功能描述:localtime()将参数timep指向的time_t时间信息转换成以tm结构体表示的本地时区时间(如北京时间=GMT+小时)。
    例:

    [cpp]view plain

  • intmain(void)

  • {

  • char*wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

  • time_ttimep;

  • structtm*p_tm;

  • timep=time(NULL);

  • p_tm=localtime(&timep);/*获取本地时区时间*/

  • printf("%d-%d-%d",(p_tm->tm_year+1900),(p_tm->mon+1),p_tm->tm_mday);

  • printf("%s%d:%d:%d ",wday[p_tm->tm_wday],p_tm->tm_hour,p_tm->tm_min,p_tm->tm_sec);

  • return0;

  • }


  • 2.5mktime()函数
    头文件:#include<time.h>
    函数定义:time_tmktime(structtm*p_tm);
    功能描述:mktime()将参数p_tm指向的tm结构体数据转换成从1970年1月1日00时00分00秒至今的GMT时间经过的秒数。
    例:

    [cpp]view plain

  • intmain(void)

  • {

  • time_ttimep:

  • structtm*p_tm;

  • timep=time(NULL);

  • pintf("time():%d ",timep);

  • p_tm=local(&timep);

  • timep=mktime(p_tm);

  • printf("time()->localtime()->mktime():%d ",timep);

  • return0;

  • }


  • 2.6asctime()函数
    头文件:#include<time.h>
    函数定义:char*asctime(conststructtm*p_tm);
    功能描述:asctime()将参数p_tm指向的tm结构体数据转换成实际使用的时间日期表示方法,并以字符串形式返回(与ctime函数相同)。字符串格式为:"WedJun2021:00:002012 "。
    例:

    [cpp]view plain

  • intmain(void)

  • {

  • time_ttimep;

  • timep=time(NULL);

  • printf("%s ",asctime(gmtime(&timep)));

  • return0;

  • }


  • 2.7difftime()函数
    头文件:#include<time.h>
    函数定义:doubledifftime(time_ttimep1,time_ttimep2);
    功能描述:difftime()比较参数timep1和timep2时间是否相同,并返回之间相差秒数。
    例:

    [cpp]view plain

  • intmain(void)

  • {

  • time_ttimep1,timep2;

  • timep1=time(NULL);

  • sleep(2);

  • timep2=time(NULL);

  • printf("thedifferenceis%fseconds ",difftime(timep1,timep2));

  • return0;

  • }


  • 2.8gettimeofday()函数
    头文件:#include<sys/time.h>
    #include<unistd.h>
    函数定义:intgettimeofday(structtimeval*tv,structtimezone*tz);
    功能描述:gettimeofday()把目前的时间信息存入tv指向的结构体,当地时区信息则放到tz指向的结构体。
    structtimezone原型:

    [cpp]view plain

  • structtimezone{

  • inttz_minuteswest;/*miniuteswestofGreenwich*/

  • inttz_dsttime;/*typeofDSTcorrection*/

  • };

  • 例:

    [cpp]view plain

  • structtimevaltv;

  • structtimevaltz;

  • gettimeofday(&tv,&tz);


  • 附:
    使用time函数族获取时间并输出指定格式字符串例子(strftime()函数):

    [cpp]view plain

  • intmain(void)

  • {

  • charstrtime[20]={0};

  • time_ttimep;

  • structtm*p_tm;

  • timep=time(NULL);

  • p_tm=localtime(&timep);

  • strftime(strtime,sizeof(strtime),"%Y-%m-%d%H:%M:%S",p_tm);

  • return0;

  • }


  • 2.9settimeofday()函数
    头文件:#include<sys/time.h>
    #include<unistd.h>
    函数定义:intsettimeofday(conststructtimeval*tv,conststructtimezone*gz);
    功能描述:settimeofday()把当前时间设成由tv指向的结构体数据。当前地区信息则设成tz指向的结构体数据。
    例:

    [cpp]view plain

  • intmain(void)

  • {

  • chart_string[]="2012-04-2822:30:00";

  • structtmtime_tm;

  • structtimevaltime_tv;

  • time_ttimep;

  • intret=0;

  • sscanf(t_string,"%d-%d-%d%d:%d:%d",&time_tm.tm_year,&time_tm.tm_mon,&time_tm.tm_mday,&time_tm.tm_hour,&time_tm.tm_min,&time_tm.tm_sec);

  • time_tm.tm_year-=1900;

  • time_tm.tm_mon-=1;

  • time_tm.tm_wday=0;

  • time_tm.tm_yday=0;

  • time_tm.tm_isdst=0;

  • timep=mktime(&time_tm);

  • time_tv.tv_sec=timep;

  • time_tv.tv_usec=0;

  • ret=settimeofday(&time_tv,NULL);

  • if(ret!=0)

  • {

  • fprintf(stderr,"settimeofdayfailed ");

  • return-1;

  • }

  • return0;

  • }



Ⅲ linux shell 自定义加法函数 急求

$?是返回最近一条命令的返回值,echo $total,$?的意思是返回echo $total的返回值,这里肯定是成功返回,自然是0了,如果需要fSum返回值,那么需要在fSum命令后直接$?即可.

subShellInfo=$(fSum 3 2)
total=$?
echo $total,$?
那么就显示5 0

其中subShellInfo是子进程中所有输出信息,第一个$?是子进程返回值

Ⅳ linux如何添加自己的系统函数

你这个不叫系统函数,系统函数是操作系统内核提供给应用程序调用的接口。
你这个就是个应用程序,自己写个程序hello.c如下:
#include <stdio.h>

void main()
{
printf("Hello world!\n");
}
然后再用gcc编译成可执行程序:
gcc -o hello hello.c
这时候在当前目录下就会生成一个叫hello的可执行程序,输入./hello之后就会打印出Hello world!了。如果你不想输入目录的话,你也可以把这个hello可执行程序所在的目录加入到path环境变量中就可以了。

Ⅳ linux 脚本怎么定义子shell能用的函数

看如下示例,可以实现把函数传递到子shell中,子shell在linux脚本中使用()实现,即在()中的代码会在子shell中执行,代码如下:

#!/bin/bash
#Scriptname:do_square
functionsquare{
localsq#sqislocaltothefunction
let"sq=$1*$1"
echo"Numbertobesquaredis$1."
echo"Theresultis$sq"
}
echo"Givemeanumbertosquare."
readnumber
value_returned=$(square$number)#子shell
echo"$value_returned"

执行效果如下:

Ⅵ 如何查找Linux的函数定义的位置

鼠标光标停留在函数处,利用快捷键F12 函数名字放到搜索栏,进行搜索,从搜索的结果中找到定义处

Ⅶ Linux 下如何快速查找到头文件和函数定义

如:grep “time_t” /usr/include/*.h |grep “typedef”可以查找到“typedef_time_t time_t;”
Locatekeyword.h 可以查找名为keyword 的头文件所在地目录树

使用linux系统难免会忘记文件所在的位置,可以使用以下命令对系统中的文件进行搜索。搜索文件的命令为”find“;”locate“;”whereis“;”which“;”type“
linux下最强大的搜索命令为”find“。它的格式为”find <指定目录> <指定条件> <指定动作>“;比如使用find命令搜索在根目录下的所有interfaces文件所在位置,命令格式为”find / -name 'interfaces'“
使用locate搜索linux系统中的文件,它比find命令快。因为它查询的是数据库(/var/lib/locatedb),数据库包含本地所有的文件信息。使用locate命令在根目录下搜索interfaces文件的命令为”locate interfaces“
使用”whereis“命令可以搜索linux系统中的所有可执行文件即二进制文件。使用whereis命令搜索grep二进制文件的命令为”whereis grep“。
使用which命令查看系统命令是否存在,并返回系统命令所在的位置。使用which命令查看grep命令是否存在以及存在的目录的命令为”which grep“
使用type命令查看系统中的某个命令是否为系统自带的命令。使用type命令查看cd命令是否为系统自带的命令;查看grep 是否为系统自带的命令。

Ⅷ linux 如何自定义命令函数

你是想问在shell(比如说bash)下如何定义一个函数cuts吗?

如果是bash,那么就直接在shell 下输入以下内容

function cuts () {
echo "Hello world"
}

然后就可以在当前终端下调用cuts了,比如
$ cuts
Hello world

如果你是想在某个脚本中调用函数cuts,那么只要把上面那段代码加入脚本中,也就可以用了,比如

#!/bin/bash

function cuts ()
{
echo "Hello world"
}

....
cuts
....

Ⅸ linux 内核 函数

像这样全部大写的一般应该是个宏定义。在mips_machine.h中:

/*
*Copyright(C)2008-2010GaborJuhos<[email protected]>
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodifyit
*
*bytheFreeSoftwareFoundation.
*
*/
#ifndef__ASM_MIPS_MACHINE_H
#define__ASM_MIPS_MACHINE_H
#include<linux/init.h>
#include<linux/stddef.h>
#include<asm/bootinfo.h>
structmips_machine{
unsignedlongmach_type;
constchar*mach_id;
constchar*mach_name;
void(*mach_setup)(void);
};
#defineMIPS_MACHINE(_type,_id,_name,_setup)
staticconstcharmachine_name_##_type[]__initconst
__aligned(1)=_name;
staticconstcharmachine_id_##_type[]__initconst
__aligned(1)=_id;
staticstructmips_machinemachine_##_type
__used__section(.mips.machines.init)=
{
.mach_type=_type,
.mach_id=machine_id_##_type,
.mach_name=machine_name_##_type,
.mach_setup=_setup,
};
externlong__mips_machines_start;
externlong__mips_machines_end;
#ifdefCONFIG_MIPS_MACHINE
intmips_machtype_setup(char*id)__init;
voidmips_machine_setup(void)__init;
#else
staticinlineintmips_machtype_setup(char*id){return1;}
staticinlinevoidmips_machine_setup(void){}
#endif/*CONFIG_MIPS_MACHINE*/
#endif/*__ASM_MIPS_MACHINE_H*/

Ⅹ linux下的函数声明问题

函数声明的作用在于告诉编译器,在编译到调用这个函数的语句的时候,检查调用语句的参数个数、类型和顺序是否正确,不正确给出提示

如果你的函数书写在了调用语句之前,则由于编译器在编译到调用语句之前已经编译过这个函数,认识它,于是这时候没有声明也可以。但如果你这个函数书写在了调用语句之后,由于编译器是从前往后编译代码的,所以就会出现不认识的情况,就会提示出错。函数声明之所以写在代码的最前面,也是这个道理,目的就是告诉编译器,我后边有个函数是某某样子的,你得记着,它的实现代码这时候你写在哪儿就无所谓了。
你得情况可能就是,你先编译了自定义函数所在的
cpp
,而后编译的
主函数所在
cpp
,所以没声明也可以使用。

热点内容
阿里云怎么领服务器 发布:2024-10-09 05:17:53 浏览:816
c语言可逆素数 发布:2024-10-09 05:13:44 浏览:920
班级采访问题 发布:2024-10-09 04:45:44 浏览:497
单人地图脚本 发布:2024-10-09 04:45:32 浏览:754
易语言cf自瞄源码 发布:2024-10-09 04:36:14 浏览:121
安卓和苹果哪个更难修理 发布:2024-10-09 04:36:12 浏览:26
黎明觉醒安卓什么配置 发布:2024-10-09 04:32:05 浏览:127
助手autojs脚本 发布:2024-10-09 04:31:40 浏览:186
sql判断今天 发布:2024-10-09 04:19:35 浏览:943
拆分视频需要哪些配置 发布:2024-10-09 04:06:39 浏览:912