954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Fork()

I'm doing a OS class.

Trying to implement this pseudo code:

* Forking is fun! ­ Simple tips
First, fork the child process:

pid_t ForkPID;
ForkPID = fork();
Then write a quick switch statement!

switch (ForkPID) {
// ­-1, fork failure
case ­-1:
printf("Error: Failed to fork.\n"); break;
// 0, this is the child process
case 0:
break;
// > 0, parent process and the PID is the child's PID
default:
}
I get an error:

ForkEnc.cc:18: error: stray ‘\302’ in program
ForkEnc.cc:18: error: stray ‘\255’ in program

line 18 is:

case -­1:


can someone help me out.

drjay1627
Junior Poster in Training
91 posts since Nov 2008
Reputation Points: 12
Solved Threads: 1
 

I may be wrong but what I feel is the pid_t data type within switch() is causing the error with -1. As negativity of the choice element is not correctly defined in some cases its better if you use an integer variable to hold the ForkPid value.

as
int pid;
.
.
pid=fork();
.
.
switch(pid)
{
.
.
}

This will satisfy your needs as the returned value of pid from a child process shall always come within the limits of signed integers.

csurfer
Posting Pro
568 posts since Jan 2009
Reputation Points: 485
Solved Threads: 88
 

didn't fix the error...

drjay1627
Junior Poster in Training
91 posts since Nov 2008
Reputation Points: 12
Solved Threads: 1
 

The same code compiled for me.
Platform HP-UX

Which is yours?

ahamed101
Junior Poster
117 posts since Jul 2008
Reputation Points: 51
Solved Threads: 14
 

Hi,
I googled and found this... Hope it is not an offence to place links to other forums for information...

http://ubuntuforums.org/showthread.php?t=381626

Check that it might help you... The actual issue is there are some invisible characters... Good Luck...

ahamed101
Junior Poster
117 posts since Jul 2008
Reputation Points: 51
Solved Threads: 14
 

i copied a code online from some MS power point slide. the ' in text files and in Microsoft applications are different. makes sense ever tried to write an email in word and copy it onto a gmail back in the day. you use to get weird character at '.

thanks ahamed101!

drjay1627
Junior Poster in Training
91 posts since Nov 2008
Reputation Points: 12
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You