Implementation of dual-process operation in C language under Linux

Source: Internet
Author: User

Topic

Write a Linux C program, in the main process to create a child process, the child process in the dead loop output "Hello CSU" string, the main process sleep 10s, the child process to send a signal to end the child process, and then the main process exits. (Signaling for interprocess communication, kill function)

Code
#include <stdio.h>#include <signal.h>#include <sys/types.h>#include <unistd.h> #include <stdlib.h>void Main () {pid_t pid; printf ( "program is starting\n"); Pid=fork (); switch (PID) {case- 1: exit (0); break; case  0: while ( 1) {Sleep (1); printf ( "Hello world\n");} break; default:sleep (10);//signaled the terminating signal 
printf ("End subprocess \ n"); Kill (PID, SIGTERM); break;}
Run results

Implementation of dual-process operation in C language under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.