[ back to toc ]

Help on Railway reservation system using C and unix

Date: 2002/05/09 12:48

We have a project to be done in C and unix which involves the railway
reservation system.
It is to be implementd using C as the Front end with unix as the server
The main part of our project is that we have to block two users
simultaneously trying to book a same ticket.
We have used C files as the database.
How do we interface c with Unix
We are using Turbo C and Linux

To be honest: I would not do it using a C fornt-end. I would rather do it
using Web application (maybe CGI, or something more powerful). I assume
that this is going to be home-work (getting to the end of the year many
such questions arise altough there was the hole semester to do the work. I
know I was student, and t students I teach come up with the questions
these days... It is not a problem.)

What you need is writing a server program and a client program. The two
programs have to communicate using some inter process communication. There
are several possibilities: pure socket implementation, CORBA, RPC adn so
on. I have only experience with socket programmign, all others are higher
level interfaces built on top of socket programming.

To learn socket programming read Beej's Guide (seek google for it, easy to

The easiest solution on the server side is to write a program that runs
started by 'inetd'. This way your program can also be tested on the
command line typing the characters expected to come over the net and
seeing the characters answered by the program on the screen. (Program
started by inetd get network input on stdin and should send stdout the

Ensuring that you do not sell a ticket twice you have to use some locking
method. This can be based on pthread locking mechanism if you implement a
single process. multi-thread daemon (not the inetd solution) or file
locking (fcntl or flock BSD style system call).

Please Followup To my problem
Thanks a lot for the reply.
But I need more help . Can you tell me how exactly i go about doing this.
The thing is i have to submit it before 20th May.
and i do not know anything about socket prog. What does it do and how do i
start implementing it.Please tell me more. Our project guide has told us
to use Semaphores or Any form of IPC to avoid the simultaneous access
problem. But can i apply semahpores to C files (DATAFILES)

Please Let me know in detail if you can.

>use Semaphores or Any form of IPC
>to avoid the simultaneous access problem

You can use POSIX thread mutexes from within the same program in several
threads. The issue with the semaphore is the following:

1. Semaphore is a general word, not a specific implementation. A POSIX
thread mutex is a kind of semaphore. There can be several types of

2. The BSD system call flock is also a kind of semaphore, though your
guide most probably does not refer to this one.

3. When there is a semaphore on the railway the trains take it into
account, but the semaphore only helps them not to collide. If a train does
not care the semaphore then the trains crash. The same is in computing.
All programs should know what a semaphore works for and should respect.
The semaphore itself does not know what to protect.

>But can i apply semahpores to C files (DATAFILES)

Yes. You can apply to that, it is only the matter of the program code that
the program will not access the file is the semaphore is set by some other
program. But it is vital that you understand that there is no code that
physically connects the semaphore to the resource that it protects. This
binding is the program code itself, how the programs behave.


[ back to toc ]