Member Avatar for Josue198s

hi guys please help writing this shell script in C..please

count2:

#! /bin/sh
# count2 also increments and appends a value to the numbers file
# but only when it can successfully create a new hard link to the numbers file
 
count=0
while [ $count -lt 200 ]      # still loop 200 times
do
   count=`expr $count + 1`    # increment the loop counter
   if ln numbers numbers.lock # try to enter the critical region
   then                       # in this case, ln is similar to TSL
      n=`tail -1 numbers`     # get the last number to increment
      expr $n + 1 >> numbers  # increment it and append it to the file
      rm numbers.lock         # exit the critical region
   fi                         # Note that if the ln was unsuccessful, we don't
                              # do busy waiting, but just continue looping
done

Do you want a C program that acts like this Bourne shell script? Or a csh script that acts like this sh script?

Either way, you need to start the work and post your code, possibly not yet running / compiling. Be sure to show the full errors if you have them.

What is the point of this code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.