shm sem fork etc... Please help


 
Thread Tools Search this Thread
Top Forums Programming shm sem fork etc... Please help
# 1  
Old 02-28-2006
Question shm sem fork etc... Please help

Smilie 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));
}

# 2  
Old 02-28-2006
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 ?
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Increasing size for /dev/shm

Hello, How do I increase the size of /dev/shm ? Additional pv have been added and rootlv has been extended How can I extend /dev/shm? Best regards, Vishal (1 Reply)
Discussion started by: admin_db
1 Replies

2. Shell Programming and Scripting

How to add nodev for /dev/shm partition in Linux using shell script?

Hi, Please guide me how to add nodev option for /dev/shm partition. I am new to scripting and looking to do via command line. Thanks Litu (13 Replies)
Discussion started by: Litu1988
13 Replies

3. UNIX for Advanced & Expert Users

/dev/shm space in red hat linux

I am using redhat linux machine and oracle11g version. /dev/shm shows 88%. Will this be freed automatically? OR should i clean any files? >df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/systemvg-rootvol 7.6G 2.2G 5.1G 30% /... (5 Replies)
Discussion started by: govindts
5 Replies

4. Solaris

zone.max-sem-ids -- ???

Hi, OS = Solaris10 Can someone please advise what is the difference between the following two (2) output of the prctl commands? # prctl -n zone.max-sem-ids $$ process: 18782: -sh NAME PRIVILEGE VALUE FLAG ACTION RECIPIENT zone.max-sem-ids ... (0 Replies)
Discussion started by: newbie_01
0 Replies
Login or Register to Ask a Question