fork() with cygwin

Hello,

I tried some test to see cygwin can do fork() on Windows XP, sample code:

value=10

int pid
pid=fork()

if [ pid < 0 ]
  fprintf(stderr, "fork() failed")
else if [ pid == 0 ]
  value += 10;
  printf("Child: Value = %d\n", value)
else if [ pid > 0 ]
  wait(NULL);
  printf("Parent: Value = %d\n", value)

But I am getting error indicated fork() is not support by cygwin:

"value=10
+ value=10

int pid
+ int pid
fork_example.sh: line 3: int: command not found
pid=fork()
fork_example.sh: line 4: syntax error near unexpected token `('
fork_example.sh: line 4: `pid=fork()'  "

Any Guru out there have an alternative to fork on cygwin?  Or is my code just wrong?

Many Thanks.
tranicusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WerrockCommented:
Hmm, that is not much C code. Where are all the semi colons and if cases use (), not [].
I tested with this code and it compiled in cygwin.
#include <unistd.h>
int main()
{
      pid_t pid;
      pid =fork();
      return 0;
}
0
tranicusAuthor Commented:
Thanks Werrock,

I forgot to add, I am not doing C just a straight Shell Script in Cygwin.
0
WerrockCommented:
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

tranicusAuthor Commented:
So iis there an alternative to pull this off in Shell for Cygwin environment?
0
WerrockCommented:
Basically they just launch another script inside it when they need something done in parallel. You still have not declared what your fork will be used for.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
geoffryfCommented:
Guys, need some help, i don't understand what should I include?  I download and installed all the package using the setup.exe provided by cygwin. Now exactly what do I do to fork the process?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.