The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
fork() help alexicopax High Level Programming 3 03-08-2007 01:08 AM
Fork () iwbasts High Level Programming 5 11-09-2005 01:39 AM
Fork or what? crippe High Level Programming 0 03-08-2005 02:21 AM
fork() MKSRaja High Level Programming 2 02-07-2005 08:55 AM
Fork Deepali UNIX for Dummies Questions & Answers 5 08-26-2001 05:14 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-27-2006
Dana73's Avatar
Registered User
 

Join Date: Feb 2006
Location: St Louis, MO
Posts: 3
Question shm sem fork etc... Please help

This is already my n-th attempt to write this program. Some help would be appreciated. I have created some children processes, a couple of them writes to a shared memory (array of ints, where the first element is the "counter" of all elements in the array). The other child deletes an element from the shared mem. I placed semaphores in appropriate places (I think) to protect the critical sections. But then each child is supposed to print out the whole array one character at a time. I did it like this:
note: buff is the pointer to the shm segment. I think the problem lies with the marked lines...(gcc gives me warnings there)
Code:
for(j = 0; j < 50; j++) {
   if((*cnt) >= 29) /* array full, counter is a ptr to 1st el */
      ;
   else {
      (*cnt)++;
      rand_n = random_num(26, 97);
      fprintf((buff + (*cnt)*sizeof(int)), "%c ", rand_n);
   } /* end of writing cs */
}
for(k = 0; k < (*counter); k++) {
    rand_n = random_num(990001, 1000000);
    usleep(rand_n);
    fprintf(stdout, "%c ", buff + k*sizeof(int));
}
Reply With Quote
Forum Sponsor
  #2  
Old 02-28-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Quote:
fprintf((buff + (*cnt)*sizeof(int)), "%c ", rand_n);
stream specification, where the formatted print message to be redirected is missing!!!

what is the datatype of buff ?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0