Segmentation fault in client - server programming in Linux
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Segmentation fault in client - server programming in Linux
Hi,
i made server program in c on linux, accepting portno as argument, and i made client program on same architecture accepting hostname & portno as arguments, but when i run client on same machime in which i ran server, it is giving error " Segmentation fault".
The point I was trying to make was that there was not nearly enough information
in your post to help. You didn't post a single line of code. How are we supposed
to know what the problem is then?
I suggest that you create the simplest possible, but still complete and compilable,
test program that exhibits the error and post it here enclosed in code tags.
But first you should step through the crashing program with a debugger, monitoring
every variable that is in scope. Identify the line that makes it crash and at least
post that line along with the definitions of the variables being used in it.
A segmentation fault most likely means that you are tampering with memory that is not yours to tamper with. Maybe you're trying to use a pointer that is not yet pointing to memory you are allowed to read/write. Since you seem so stumped by a segmentation fault I get the feeling that
your grasp of the core C language is poor and you should probably master it to a higher
degree before starting to use networking libraries and other platform specific stuff.
Also, make sure you turn all warnings on, that could help you find the problems faster.
can u pls tell me how can i debug my program line by line ?
sure, there is a debugger called gdb. You will need to look around for help on how to use it (man, google) but you can get a great deal of information from it.
First thing i would check is that i actually have 3 arguments passed in from the command line. You access argv[2] are you sure you have that many arguments passed in.
yes client has 2 arguments "hostname" & "portno", while server has only one arg "portno", after running server i run client then it gives segmentation fault on client side.
if you can't find what is causing the trouble by using gdb, use valgrind with the --db-atach=yes flag, and it will dump you in the debugger with a short description of the first illegal memory access.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.