嵌入式Linux应用程序开发期末考试题库及答案

发布时间 : 星期三 文章嵌入式Linux应用程序开发期末考试题库及答案更新完毕开始阅读

D、pc=open(buf) 1

下面的程序建立一个守护进程,该守护进程每隔10s在/tmp/dameon.log中写入一个字符串。请选出应填写在空白处的选项。 #define MAXFILE 65535 int main() { pid_t pc; int i,fd,len; char *buf=\is a Dameon\\n\ len =strlen(buf); /*第一步*/ pc=fork(); if(pc<0) { printf(\\\n\ exit(1); } else if(pc>0) exit(0); /*第二步*/ setsid(); /*第三步*/ chdir(\ /*第四步*/ umask(0); /*第五步*/ __________ close(i); /*守护进程创建完成,以下开始正式进入守护进程工作*/ while(1) {

if((fd=open(\

{ perror(\ exit(1); } write(fd, buf, len+1); close(fd); sleep(10); } } A、for(i=3;i< MAXFILE;i--) B、for(i=0;i< MAXFILE;i--) C、for(i=3;i< MAXFILE;i++) D、for(i=0;i< MAXFILE;i++) 4

hello.c和hello.h位于同一目录下,源代码如下所示。 /*hello.c*/ int main() { printf(\everyone!\\n\} /*hello.h*/ #include 要求编写Makefile文件实现对这两个文件的编译,Makefile文件如下所示。请选出应填写在空白处的选项。 /*Makefile*/ hello:hello.c hello.h __________ A、gcc hello.c&hello.h -o hello B、gcc hello.c hello.h -o hello C、make hello.c&hello.h -o hello D、make hello.c hello.h -o hello 2

下面的程序建立一个守护进程,然后在该守护进程中新建一个子进程,该子进程暂停10s,然后自动退出,并由守护进程收集子进程退出的消息。子进程退出后,守护进程循环暂停,其间隔时间为10s。子进程和守护进程的退出消息均在/var/log/messages中输出。请选出应填写在空白处的选项。 #define MAXFILE 65535 int main(void) { pid_t child1,child2; int i; child1 = fork(); if( __________ ) { perror(\fork\ exit(1); } else if( child1 > 0 ) exit( 0 ); openlog(\LOG_PID, LOG_DAEMON); setsid(); chdir( \ umask( 0 ); for( i = 0 ; i < MAXFILE ; i++ ) { close( i ); } child2 = fork(); if( child2 == -1 ) { perror(\fork\ exit(1); } else if( child2 == 0 ) { syslog( LOG_INFO, \ sleep(10); syslog( LOG_INFO, \child2 is going to exit! \ exit(0); } else { waitpid( child2, NULL, 0); syslog( LOG_INFO , \child1 noticed that child2 has exited \ closelog(); while(1) { sleep(10); } } } A、child1 == -1 B、child1 == 0 C、child1 > 0 D、child1 >= 0 1

下面的程序实现对文件属性的查询。请选出应填写在空白处的选项。 static int get_file_size_time(const

char

*filename) { {

struct

stat stat

statbuf; on %s }

if(stat(filename,&statbuf)==-1) if(S_ISDIR(statbuf.st_mode))

printf(\

Error:%s\\n\return(-1);

return(1); if(S_ISREG(statbuf.st_mode))

printf(\ return(0); } int main(int argc,char **argv) { DIR *dirp; struct dirent *direntp; int stats; if( __________ ) { printf(\filename\\n\\a\ exit(1); } if(((stats=get_file_size_time(argv1))==0)||(stats==-1))exit(1); if((dirp=opendir(argv1))==NULL) { printf(\Directory %s Error:%s\\n\

exit(1);

}

while((direntp=readdir(dirp))!=NULL) if(get_file_size_time(direntp->d_name)==-1) break; closedir(dirp); exit(1); } A、argc!=1 B、argc!=2 C、argv!=1 D、argv!=2 1

程序设计题4

下面的程序实现文件的拷贝。请选出应填写在空白处的选项。 #define BUFFER_SIZE 1024 int main(int argc,char **argv) { int from_fd,to_fd; int bytes_read,bytes_write; char bufferBUFFER_SIZE; char *ptr; if( __________ ) { fprintf(stderr,\fromfile

tofile\\n\\a\

exit(1);

} }

if((from_fd=open(argv1,O_RDONLY))==-1) { fprintf(stderr,\%s Error:%s\\n\

exit(1);

if((to_fd=open(argv2,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR))==-1)

{ fprintf(stderr,\%s Error:%s\\n\ exit(1); } while(bytes_read=read(from_fd,buffer,BUFFER_SIZE))

{ if((bytes_read==-1)&&(errno!=EINTR)) break; else if(bytes_read>0) { ptr=buffer; while(bytes_write=write(to_fd,ptr,bytes_read)) { if((bytes_write==-1)&&(errno!=EINTR)) break; else

if(bytes_write==bytes_read) break; else if(bytes_write>0) {

ptr+=bytes_write;

bytes_read-=bytes_write; } } if(bytes_write==-1) break; } } close(from_fd); close(to_fd); exit(0); } A、argc!=0 B、argc!=1 C、argc!=2 D、argc!=3 4

下面的程序实现对字符串倒序输出。请选出应填写在空白处的选项。 int display1 (char

*string) { printf (\ __________ { char *string2; int size,i; size = strlen (string1); string2 = (char *) malloc (size + 1); for (i = 0; i< size; i++) string2[size+1] = ' '; printf(\{ char string[] = \ display1 (string); display2 (string); } A、int display2 (char *string) B、int display2 (char *string1) C、int display2 (char *string2) 2

下面的程序实现对字符串倒序输出。请选出应填写在空白处的选项。 int display1 (char *string) { printf (\original string is %s \\n\string); } int display2 (char *string1) { char *string2; int size,i; size = strlen (string1); string2 = (char *) malloc (size + 1); for (i = 0; i< size; i++) __________ ; string2[size+1] = ' '; printf(\string afterward is %s\\n\} int main () { char string[] = \ display1 (string); display2 (string); }

A、string2[size - i -1] = string1[i] B、string2[size - i ] = string1[i] C、string2[size - i + 1] = string1[i] D、string2[size - i ] = string1[i+1] 1

联系合同范文客服:xxxxx#qq.com(#替换为@)