Linux - SoftwareThis 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
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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()?
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?
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.
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.
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'.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.