⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 create.c

📁 这个是学习嵌入式开发的重要例子
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <sys/stat.h>#include <semaphore.h>#include <string.h>#include <errno.h>#include <fcntl.h>int main(int argc, char **argv){  if (argc < 2)  {    fprintf(stderr, "Usage: %s <name>\n", argv[0]);    exit(1);  }  sem_t *sem = NULL;  unsigned int value;  value = 1;  //Upon  successful  completion,  the sem_open() function shall return the address of the semaphore. Other-  //wise, it shall return a value of SEM_FAILED and set errno to indicate the error. The  symbol  SEM_FAILED  //is  defined  in  the  <semaphore.h>  header. No successful return from sem_open() shall return the value  //SEM_FAILED.  //sem_t *sem_open(const char *name, int oflag, ...);  if ((sem = sem_open(argv[1], O_CREAT | O_EXCL, 0644, value)) == SEM_FAILED)  {    fprintf(stderr, "sem_open() failed: %s\n", strerror(errno));    exit(1);  }  fprintf(stdout, "sem_open() successed.\n");  //int sem_close(sem_t *sem);  sem_close(sem);  //int sem_unlink(const char *name);  //sem_unlink(argv[1]);  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -