📄 mprocess.c
字号:
#include "config.h"//#include <unistd.h>#define LED 16 // P2.16 controles LED1#define BEEP 7 // P0.7 controles BEEPint main(void){ int fd, fd2; uint32 val; pid_t child; fd = open("/dev/P0", O_RDONLY); if(fd == -1) { printf("\nCan't open P0!\n"); exit(-1); } fd2 = open("/dev/P2", O_RDONLY); if(fd == -1) { printf("\nCan't open P2!\n"); exit(-1); } ioctl(fd, GPIO_SET_PIN_OUT, BEEP); ioctl(fd2, GPIO_SET_PIN_OUT, LED); ioctl(fd, GPIO_SET_PIN, BEEP); ioctl(fd2, GPIO_SET_PIN, LED); printf("\nTry to create new process.\n"); child = vfork(); switch(child) { case -1: // fault perror("vfork error\n"); exit(-1); case 0: // child process { printf("This is child, BEEP is running\n"); ioctl(fd, GPIO_CLR_PIN, BEEP); sleep(1); ioctl(fd, GPIO_SET_PIN, BEEP); sleep(1); exit(0); } default: // father process { printf("This is father, LED is lighting.\n"); while(1) { ioctl(fd2, GPIO_CLR_PIN, LED); sleep(1); ioctl(fd2, GPIO_SET_PIN, LED); sleep(1); } } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -