LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-11-2010, 10:25 AM   #1
ninja123
LQ Newbie
 
Registered: Mar 2009
Posts: 15

Rep: Reputation: 0
Knowing PID of client


Hi All,

I have now started doing socket programming in linux.
I have a server and client tasks with the client bound to the socket(Datagram). The client and server would then send messages.
However, I need the server to know the "Pid" of the client talking with it.
How is this possible? Can I get this info from some structure that can be passed by the client to the server during a sendto()?

Thanks in advance!
 
Old 05-11-2010, 12:46 PM   #2
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
Hi, why do not simply send the process id reported by getpid() as normal data or control data using sendto, when the client establishes the connection?
 
Old 05-11-2010, 01:17 PM   #3
Porch
LQ Newbie
 
Registered: Feb 2010
Location: Los Alamos, NM
Distribution: Mint
Posts: 10

Rep: Reputation: 0
I just had a project like this last semester
Your "server" doesn't need to know the PID of the "client" to connect, so i would just do as irmin suggested and have the client getpid(), then send it to the server.
 
Old 05-12-2010, 02:24 AM   #4
ninja123
LQ Newbie
 
Registered: Mar 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Hi all,

Thanks for your suggestions. Actually, shouldn't the server know who its clients are?

I am currently writing a sort of filter server which allows only genuine clients and blocks malicious clients.

Of course, the term genuine and malicious are found depending on what information the clients ask. If the clients are found to be malicious, then the server has to do a 'POSIX' kill on the client (using its PID).

I have no linux experience but have worked with QNX where I use message passing(not sockets) and there was a client info struct
that gave the client pid.

Can you guys help me?
 
Old 05-12-2010, 05:12 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If the client is an external system talking to your socket, then there is no process on the server that corresponds to the client. Your server just has to check eg ip addr and you can write it so that it expects a password and dumps the cxn if it's invalid.
Even if you ran the client SW on the same box, the same rule applies. You don't kill the client process even the, just refuse/ignore the cxn if its 'bad/invalid'.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the more easier way to check the pid and kill the pid cmx08 Linux - General 5 09-09-2008 10:57 PM
reading pid from pid file in C language shifter Programming 1 05-14-2008 10:49 AM
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 07:48 PM
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 10:32 PM
ERROR: Couldn't write pid to pid file lawrencegoodman Linux - Newbie 2 02-13-2004 08:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration