Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

C program

Original Message
Name: lisa
Date: March 28, 2006 at 12:55:04 Pacific
Subject: C program
OS: xp
CPU/Ram: pentium me
Model/Manufacturer: toshiba
Comment:
i have a problem with SIGUSR1 and SIGUSR2
i coudnt understand it....

could you help me with this problem:

Write a C program (give it the name: family.c) which receives no arguments. The program should fork exactly two children. One child should sleep for 2 seconds and then send the signal SIGUSR1 to his parent. The other child should sleep for 5 seconds and then send the signal SIGUSR2 to his parent. The parent, while busy counting from 0 to 9 –sleeping one second after each count- will ignore the first signal but handle the other signal with a signal handler that just prints the following: “Son! Stop making noise!”

this my solution but without using the signal

int main (void)
{
int child_pid;
int child_pid1;
int i;



/* define the signal handler for the CHLD signal */

/* and the child process forking code... */
child_pid = fork();
switch (child_pid) {
case -1: /* fork() failed */
perror("fork");
exit(1);
case 0: /* inside child process */

sleep(2); /* sleep a little, so we'll have */
/* time to see what is going on */
exit(0);
default: /* inside parent process */
break;


child_pid1 = fork();
switch (child_pid1) {
case -1: /* fork() failed */
perror("fork");
exit(1);
case 0: /* inside child process */

sleep(5); /* sleep a little, so we'll have */
/* time to see what is going on */
exit(0);
default: /* inside parent process */
break;
}


/* parent process goes on, minding its own business... */
/* for example, some output... */
for (i=0; i<10; i++) {
printf("%d\n", i);
sleep(1); /* sleep for a second, so we'll have time to see the mix */
}

return 0;
}



Report Offensive Message For Removal


Response Number 1
Name: lchi2000g
Date: March 28, 2006 at 14:35:22 Pacific
Subject: C program
Reply: (edit)
...
default: /* inside parent process */
break; <=== The problem is here. Remove this line.


child_pid1 = fork();
switch (child_pid1) {
case -1: /* fork() failed */
perror("fork");
exit(1);
case 0: /* inside child process */

...

Luke Chi


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: C program

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




My PC has been hijacked!

Lexmark 2600 Printer Issues

btk1w1 infected start here post

Unwanted message remians on screen

Slow boot time


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC