Linux
6-Tong
a super student in BUPT!
展开
-
操作系统 Homework4 Sleeping Assistant ~线程同步
#include <pthread.h>#include <semaphore.h>#include <stdio.h>pthread_mutex_t mutex_chair;sem_t ta, stu;void *thread_ta();void *thread_stu(void *arg);int chair = 3;#define p(x) sem_wait(&x)#define v(x) sem_post(&x)int n.原创 2021-11-05 13:39:53 · 380 阅读 · 1 评论 -
操作系统--线程1
#include <pthread.h>#include <stdlib.h>#include <unistd.h>#include <stdio.h>void *thread_function(void *arg){ for (int i = 0; i < 20; i++) { printf("hello\n"); sleep(1); }}int main(){ pth.原创 2021-11-02 11:57:28 · 83 阅读 · 0 评论 -
Linux 父进程创建子进程
#include <sys/types.h>#include <stdio.h>#include <unistd.h>int value = 5;int count = 0;int main(){ pid_t pid; pid = fork(); if (pid == 0) { count ++; printf("count_pid0 = %d\n",count); print.原创 2021-10-09 12:48:45 · 1260 阅读 · 0 评论