Fedora Linux Support Community & Resources Center
  #1  
Old 18th December 2010, 03:03 PM
papori Offline
Registered User
 
Join Date: Nov 2010
Posts: 58
linuxfedorafirefox
fork: Resource temporarily unavailable

HELPPPP
i am using fedora 14 on dell latitude e6410,
i write a program in C.
using "fork"
after compile it write to me this message..............
fork: Resource temporarily unavailable

WHAT TO DO???
Reply With Quote
  #2  
Old 18th December 2010, 05:37 PM
mk27 Offline
Registered User
 
Join Date: Dec 2008
Posts: 89
linuxfedorafirefox
Re: fork: Resource temporarily unavailable

Try this:

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

int main(void) {
	int i;
	pid_t pid = fork();

	if (pid<0) {
		strerror(errno);
		return pid;
	}

	if (pid == 0) {
		for (i = 0; i < 3; i++) {
			puts("Child fork");
			sleep(1);
		}
		exit(0);
	} else {
		for (i = 0; i < 3; i++) {
			puts("Parent fork");
			sleep(1);
		}
	}

	return 0;
}
Reply With Quote
  #3  
Old 18th December 2010, 07:43 PM
papori Offline
Registered User
 
Join Date: Nov 2010
Posts: 58
linuxfedorafirefox
Re: fork: Resource temporarily unavailable

Hey thanks,
maybe u can help me with another problem..
I am try to create 2 children
Each of them will sort half of the array.
for exemple:
my array: 1,0,5,2,8,6,9,10
the first child will sort 1,0,5,2 to 0,1,2,5
the second child will sort 8,6,9,10 to 6,8,9,10
my idea was : to send to qsort the 2 parts separately.
after both finish' the father will do merge..
i wrote a working megre func', and also the comp func-that the qsort use is working.

here is my output , so i can see that it sucsseed to sort the first half.. but why not the other ...and why 3 forks ???
output:
pfork pfork
pfork 0 1 2 5 8 6 9 10
1 0 5 2 8 6 9 10
to that code:
Code:
 01  for(k=0;k<2;k++){
02	    pfork = fork ();// fork kid
03	    if ( pfork == -1 ){//fork failed
04	        perror("fork");
05	        exit (3);
06	    }
07	    if (pfork==0){//only kid
08	      printf("pfork ");
09	      qsort(arr+(k*(4)),4,sizeof arr[0],comp);
10	       
11	    }
12	}
13	     
14	if (pfork!=0)
15	 for (  q = 0; q < p; q++ )
16	    wait(NULL);
17	    
           merge(arr);
18	     if(pfork!=0)
19	   for( i =0 ; i<n; i++)
20	     printf("%d ",arr[i]);
thanx!
Reply With Quote
  #4  
Old 18th December 2010, 09:13 PM
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,994
linuxfedorafirefox
Re: fork: Resource temporarily unavailable

Just a suggestion for your sort. You probably want to use threads and not separate processes for this. That way you don't have to set up an IPC mechanism to merge the results.

Fork gives the child an exact copy of data, while threads can work on the same (static storage class) data.

man pthread_create


===

Also your original error "REsource temporaily ..." is errno of EAGAIN. See man fork for the cause.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe

Last edited by stevea; 18th December 2010 at 10:05 PM.
Reply With Quote
  #5  
Old 19th December 2010, 06:27 PM
mk27 Offline
Registered User
 
Join Date: Dec 2008
Posts: 89
linuxfedorafirefox
Re: fork: Resource temporarily unavailable

Quote:
Originally Posted by papori View Post
...and why 3 forks ???
Take 3 guesses

Code:
 01  for(k=0;k<2;k++){
02	    pfork = fork ();// fork kid
As mentioned, this is a task much easier to accomplish with threads.
Reply With Quote
Reply

Tags
fork, resource, temporarily, unavailable

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ipsec "Resource temporarily unavailable " seye586 Security and Privacy 0 27th October 2009 06:41 AM
nohup.out - rainlendar2: Fatal IO error 11 (Resource temporarily unavailable) on X se Thaidog Using Fedora 0 11th May 2009 01:09 AM
cdrecord: Resource temporarily unavailable. Cannot get mmap for 4198400 Bytes... whatdoineed2do Using Fedora 1 24th January 2007 11:47 PM
/usr/bin/cdrecord: Resource temporarily unavailable. Cannot get mmap for 4198400 Byte cap98 Using Fedora 8 27th June 2006 07:59 AM
cdrecord: Resource temporarily unavailable. Cannot get mmap for 8392704 Bytes on /dev jarodriguezm Using Fedora 0 7th June 2006 04:33 AM


Current GMT-time: 23:08 (Thursday, 27-11-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Highlands Coffee Travel Photos - Hard Rock Cafe, Copenhagen Travel Photos