the implement of system function.

1. We should pay attention that : Line 14 and 15 in 8_22.c was not reached whether the cmdstring is valid or invalid.
Because both of them will exit after the /bin/sh return.
2.For  while (waitpid(pid,&status,0) < 0){. Why we should use while? Because It may retry when receive EINTR, we want to get the final exit status.



./personal_system
Wed Oct 28 00:27:30 CDT 2015
return value:0
normal termination,exit status = 0
sh: hddsjafdfds: not found
return value:256
normal termination,exit status = 1
/home/tingbinz/apue.3e/SBSCODE/8
return value:8448
normal termination,exit status = 33


:cat -n 8_22.c
     1  #include "apue.h"
     2  #include <errno.h>
     3  #include <unistd.h>
     4
     5
     6  int system(const char *cmdstring)
     7  {
     8          pid_t pid;
     9          int status;
    10          if ((pid = fork()) < 0){
    11                  status = -1;
    12          }else if (pid == 0){
    13                  execl("/bin/sh","sh","-c",cmdstring, (char*) 0);
    14                  err_sys("execl:%s error",cmdstring);
    15                  _exit(127);
    16          }else{
    17                  while (waitpid(pid,&status,0) < 0){
    18                          if (errno != EINTR){
    19                                  status = -1;
    20                                  break;
    21                          }
    22                  }
    23          }
    24          return (status);
    25  }




cat -n 8_23.c
     1  #include "apue.h"
     2  #include "8_5.c"
     3  #include "8_22.c"
     4  #include <sys/wait.h>
     5
     6  int main()
     7  {
     8          int status;
     9          if ((status = system("date")) < 0){
    10                  err_sys("system () error");
    11          }
    12          printf("return value:%d\n",status);
    13          pr_exit(status);
    14
    15          if ((status = system("hddsjafdfds")) < 0)
    16                  err_sys("system () error");
    17          printf("return value:%d\n",status);
    18          pr_exit(status);
    19
    20          if ((status = system("pwd;exit 33")) < 0)
    21                  err_sys("system() error");
    22          printf("return value:%d\n",status);
    23          pr_exit(status);
    24          return 0;
    25  }
<bldc:/home/tingbinz/apue.3e/SBSCODE/8>R*_*G:cat -n 8_5.c
     1  #include "apue.h"
     2  #include <sys/wait.h>
     3
     4  void pr_exit(int status)
     5  {
     6          if( WIFEXITED(status) )
     7                  printf("normal termination,exit status = %d\n",WEXITSTATUS(status));
     8          else if (WIFSIGNALED(status))
     9                  printf("abnormal termination, signal number = %d%s\n",WTERMSIG(status),
    10  #ifdef WCOREDUMP
    11          WCOREDUMP(status) ? " (core file generated)" : "");
    12  #else
    13          "");
    14  #endif
    15          else if (WIFSTOPPED(status))
    16                  printf("child stopped, signal number = %d\n", WSTOPSIG(status));
    17  }







With the rapid development of China's economy, the per capita share of cars has rapidly increased, bringing great convenience to people's lives. However, with it came a huge number of traffic accidents. A statistical data from Europe shows that if a warning can be issued to drivers 0.5 seconds before an accident occurs, 70% of traffic accidents can be avoided. Therefore, it is particularly important to promptly remind drivers of potential dangers to prevent traffic accidents from occurring. The purpose of this question is to construct a machine vision based driving assistance system based on machine vision, providing driving assistance for drivers during daytime driving. The main function of the system is to achieve visual recognition of pedestrians and traffic signs, estimate the distance from the vehicle in front, and issue a warning to the driver when needed. This driving assistance system can effectively reduce the probability of traffic accidents and ensure the safety of drivers' lives and property. The main research content of this article includes the following aspects: 1. Implement object detection based on the YOLOv5 model. Conduct research on convolutional neural networks and YOLOv5 algorithm, and develop an object detection algorithm based on YOLO5. Detect the algorithm through road images, and analyze the target detection algorithm based on the data returned after training. 2. Estimate the distance from the front vehicle based on a monocular camera. Study the principle of estimating distance with a monocular camera, combined with parameters fed back by object detection algorithms, to achieve distance estimation for vehicles ahead. Finally, the distance estimation function was tested and the error in the system's distance estimation was analyzed. 3. Design and implementation of a driving assistance system. Based on the results of two parts: target detection and distance estimation, an intelligent driving assistance system is constructed. The system is tested through actual road images, and the operational effectiveness of the intelligent driving assistance system is analyzed. Finally, the driving assistance system is analyzed and summarized.
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值