Remote Procedure Calls

A thorough introduction to RPC for programmers of distributed systems.
Testing and Debugging the Application

The best way to test the RPC application is to run both the client and the server (the caller and callee) on the the same machine. Assuming that you are in the directory where both the client and the server reside, start the server by entering the command:

avg_svc &

The rpcinfo utility can be used to verify that the server is running. Typing the command:

$ rpcinfo -p localhost
gives the following output:
program vers proto   port
 100000    2   tcp    111  portmapper
 100000    2   udp    111  portmapper
  22855    1   udp   1221
  22855    1   tcp   1223
Note that 22855 is the program number of our application from avg.x and 1 is shown as the version number. Since 22855 is not a registered RPC application, the rightmost column is blank. If we add the following line to the /etc/rpc file:
avg        22855
rpcinfo then gives the following output:
program vers proto   port
 100000    2   tcp    111  portmapper
 100000    2   udp    111  portmapper
  22855    1   udp   1221  avg
  22855    1   tcp   1223  avg
To test the application, use the command:
$ ravg localhost $RANDOM $RANDOM $RANDOM
and the following values are returned:
value   = 9.196000e+03
value   = 2.871200e+04
value   = 3.198900e+04
average = 2.329900e+04
Since the first argument to the command is the DNS name for the host running the server, localhost is used. If you have access to a remote host that allows RPC connections (ask the system administrator before you try), the server can be uploaded and run on the remote host, and the client can be run as before, replacing localhost with the DNS name or IP address of the host. If your remote host doesn't allow RPC connections, you may be able to run your client from there, replacing localhost with the DNS name or IP address of your local system.

A Brief Look at DCE RPC

The ONC implementation of RPC is not the only one available. The Open Software Foundation has developed a suite of tools called the Distributed Computing Environment (DCE) which enables programmers to develop distributed applications. One of these tools is DCE RPC which forms the basis for all of the other services that DCE provides. Its operation is quite similar to ONC RPC in that it uses components that closely parallel those of ONC RPC.

Application interfaces are defined through an Interface Definition Language (IDL) which is similar to the language used by ONC RPC to define XDR filters. Network Data Representation (NDR) is used to provide hardware independent data representation. Instead of using programmer-defined integer program numbers to identify servers as does ONC RPC, DCE RPC uses a character string called a universal unique identifier (UUID) generated by a program called uuidgen. A program called rpcd (the RPC daemon) takes the place of portmap. An IDL compiler can be used to generate C headers and client/server stubs in a manner similar to rpcgen.

Although the entire DCE suite is commercially sold and licensed, the RPC component (which is the basis for all the other services) is available as freeware. See the references section for more information on DCE RPC.

Further Study

The sample application presented here is certainly a naive one, but it serves well in presenting the basic principles of RPCs. A more interesting set of applications can be found in the Network Information System (NIS) package for Linux (see the references section). Also, the Linux kernel sources contain an implementation of Sun's Network File System (NFS), an excellent example of the use of RPC applied to the problem of distributed file access.

In addition to distributed data access, RPC can also be used to harness the unused processing power present on most networks. The book Power Programming with RPC, listed in the references section, presents an image processing application that uses RPC to distribute CPU intensive tasks over multiple processors. With RPC, you have the capability to boost the performance of your applications without spending a dime on additional hardware.


Ed Petron is a computer consultant interested in heterogeneous computing. He holds a Bachelor of Music in keyboard performance (piano, harpsichord and organ) from Indiana University and a Bachelor of Science in computer science from Chapman College. His home page, The Technical and Network Computing Home Page at, is dedicated to Linux, The X Window System, heterogeneous computing and free software. Ed can be reached via e-mail at



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Anonymous's picture

What is difference between RPC in Windows and that of LINUX?

the steps and content are

Anonymous's picture

the steps and content are good..but if clear picture about the running RPC if given would have been very useful...any how thank u all the information about RPC...

About Version

Ravi Khadgi's picture

I'm little bit confused with the version. If we make any changes to our program, then how we update the version. Can anyone give an example for this?
You can take the following example:
version 1: adds two floating point numbers and returns floating point result
version 2(updated): returns the rounded value

regarding the rpc

Anonymous's picture

Thanks a lot for the article that you have presented. It was a lot of information. I would like to know is there any standard rpc mechanism to know about the services running over a particular machine. I need such a program to know about the processes running on a particular machine. It would be great to have your feedbacks regarding the same.

Works between ARM linux and x86 linux

Anonymous's picture


Thanks for posting the code. I tested it with server on arm-linux (Stargate xbow) and client on x86 linux. Cross compiling the code for arm-linux( just the server side files) and running /sbin/portmap on stargate will allow the rpc to register.

The program works well for C and C++ as well.

How to get ravg.c file...the

Bhupesh Chawda's picture

How to get ravg.c file...the makefile has no rule to get it...please excuse me if its a silly question..thanx

ravg.c is the code from

gigi's picture

ravg.c is the code from listing 4
avg_proc.c is the code from listing 3

The code works

Tushar's picture

It is really very useful. I am a new comer in Unix [Linux], and could develop a server/client application on RPC using this code. Thank you, Ed.

I've been reading up on RPC

South Aussie's picture

I've been reading up on RPC to implement it for our project, but this is the first tutorial I've found that presents it in a clear and readable manner and where the example code actually WORKS.
Thanks for a well written article, I wish there were more like it.

good introduction, with working program..

prashant's picture

1) link of tutorial on makefile will add its value..
i find this a good one

2)while excuting makefile "/n" creates problem.. i have deleted it from makefile and necessary file got generated..
3) try running server by ./avg_ser
and by client by ./ravg in seperate terminal..
4) i feel strongly that comment should be provided in avg_proc.c,ravg.c..
at last i am much thankful for this exceptionaly simple running tutorial..

Re: Remote Procedure Calls

Anonymous's picture

Thanks a lot. I'm a chilean engineering student and your article has been very useful for me since it explain very clearly what RPCs are and what are they used for.