Location:
Search - threecodes.rar
Search list
Description: 1、 用C语言写一个程序名字为procs4,该程序运行过程中共有4个进程,procs4程序(父进程)创建2个子进程p1和p2,p1子进程再创建一个子进程p3。4个进程完成如下工作:
父进程并打印字符串“I am main process”;p1子进程打印“I am child process p1”字符串;p2子进程打印“I am child process p2”;子进程p3打印字符串“I am child process p3”,然后使用exec(族)系统调用打印当前目录下文件和子目录下的详细信息。并且每个进程的要打印自己的pid。
2、 使用任何一种通信机制实现p1进程和p2进程之间的通信,可以使用的通信机制如:管道、消息队列、共享内存等。P1进程发送“Child process p1 is sending a message!”信息给p2进程,P2进程发送“Child process p2 is sending a message!” 信息给p1进程,p1和p2两个子进程接受信息后分别打印着两个字符串。
3、 编写程序实现生产者-消费者问题。使用linux的Pthread线程库,创建生产者和消费者两个线程,生产者线程计算当前的时间并放入缓冲区,每次计算一个时间数据;消费者线程从缓冲区读出并打印生产者计算的时间,每次打印一个时间数据。缓冲区大小为5个,生产和消费的消息数为10个,即生产和消费分别为10次。-1, using C language to write a program named procs4, the program is running a total of four processes, procs4 process (parent process) to create two sub-processes p1 and p2, p1 sub-process re-creates a child process p3. 4 key process to complete the following work:
The parent process and print the string "I am main process" p1 child process print "I am child process p1" string p2 child process print "I am child process p2" child process p3 print the string "I am child process p3 ", and then use the exec (tribe) system call to print the current directory files and subdirectories under the details. And each process, you want to print their own pid.
2, using any kind of communication mechanism to achieve the p1 and p2 the process of communication between processes, you can use the communication mechanisms such as: pipes, message queues, shared memory, and so on. Process P1 sends "Child process p1 is sending a message!" Message to the p2 process, P2 process sends "Child process p2 i
Platform: |
Size: 2048 |
Author: 杨子坤 |
Hits: