?
Solved

fork() with cygwin

Posted on 2008-11-05
6
Medium Priority
?
1,988 Views
Last Modified: 2013-11-15
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.
0
Comment
Question by:tranicus
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:Werrock
ID: 22887969
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
 

Author Comment

by:tranicus
ID: 22888193
Thanks Werrock,

I forgot to add, I am not doing C just a straight Shell Script in Cygwin.
0
 
LVL 6

Expert Comment

by:Werrock
ID: 22888324
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:tranicus
ID: 22888663
So iis there an alternative to pull this off in Shell for Cygwin environment?
0
 
LVL 6

Accepted Solution

by:
Werrock earned 500 total points
ID: 22888944
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
 

Expert Comment

by:geoffryf
ID: 23000779
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While Plesk offers many potential benefits to website administrators, including compatibility with Windows Server and other leading technologies, the company has also been working to differentiate it from other control panels for content management…
In this tutorial, we’re going to learn how to convert Youtube to mp3 for Free. We'll show you how easy it is to make an mp3 from your video clips so that you can enjoy them offline.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question