Linux Socket Programming Interview Preparation Guide
Elevate your Linux Socket Programming interview readiness with our detailed compilation of 6 questions. These questions are specifically selected to challenge and enhance your knowledge in Linux Socket Programming. Perfect for all proficiency levels, they are key to your interview success. Get the free PDF download to access all 6 questions and excel in your Linux Socket Programming interview. This comprehensive guide is essential for effective study and confidence building.6 Linux Socket Programming Questions and Answers:
1 :: How to get client port number in server socket programming?
After accepting connection on socket of server side. we can
get the client ip address and port by to functions. These
functions are belonging in "/usr/include/arpa/inet.h" header
file.
Here is some scratch from the code.
socket2 = accept(socket1, (struct sockaddr *)&client, &addrlen);
printf("%s\n",inet_ntoa(client.sin_addr));
printf("%d\n",(int) ntohs(client.sin_port));
get the client ip address and port by to functions. These
functions are belonging in "/usr/include/arpa/inet.h" header
file.
Here is some scratch from the code.
socket2 = accept(socket1, (struct sockaddr *)&client, &addrlen);
printf("%s\n",inet_ntoa(client.sin_addr));
printf("%d\n",(int) ntohs(client.sin_port));
2 :: What is the difference between socket & port?
port : a particular port number on a host
socket: a host and a port
like
-> http port = 80
-> when you fire up google.com
the socket on the server side is google.com:80 this is the server side socket
on your local system where you are browsing the socket is
yourip:port above 1024
socket: a host and a port
like
-> http port = 80
-> when you fire up google.com
the socket on the server side is google.com:80 this is the server side socket
on your local system where you are browsing the socket is
yourip:port above 1024
3 :: Why bind system call is required in socket programming?
bind system call assigns a name to the unnamed socket.
Binding an address allows a process to register its address
with the system. This makes it possible for other process to
find it.
Binding an address allows a process to register its address
with the system. This makes it possible for other process to
find it.
4 :: What is the difference between a process task and threads and what are the things that are acquired by the child process from the parent process?
Process is an executing program with several components and
proprieties.
1.exec thread
2. PID
3. priority
4. memory context
5. enviornment
6. file descriptors
7. security credentials.
processes began through a process called "fork and exec".
that is when one command starts another, the child process
first forks , the kernel copying over pages of memory from
the present process to a new location for the child process.
The child then execs, executing the new command and
overwriting the data.the thread is , which controls the flow
of the process. A process needs at least one thread.
proprieties.
1.exec thread
2. PID
3. priority
4. memory context
5. enviornment
6. file descriptors
7. security credentials.
processes began through a process called "fork and exec".
that is when one command starts another, the child process
first forks , the kernel copying over pages of memory from
the present process to a new location for the child process.
The child then execs, executing the new command and
overwriting the data.the thread is , which controls the flow
of the process. A process needs at least one thread.
5 :: What is the difference between a process task and threads?
process and task as synonymous. One or more threads
together form a process. The threads, two or more belong to
same process, share same address space of the process and
can access all the global variable of the process.
Where as two processes can't access each other's address
space and hence cant access their global variable. Two
processes can talk with each other using IPC.
what are the things that are acquired by the child
process from the parent process?
File descriptors [including socket descriptor].
The whole text segment.
Environment variables.
PPID is PID of parent process.
together form a process. The threads, two or more belong to
same process, share same address space of the process and
can access all the global variable of the process.
Where as two processes can't access each other's address
space and hence cant access their global variable. Two
processes can talk with each other using IPC.
what are the things that are acquired by the child
process from the parent process?
File descriptors [including socket descriptor].
The whole text segment.
Environment variables.
PPID is PID of parent process.
6 :: What is the difference between fork() & exec()?
fork() created a newly independent process that has it's own
space in memory and also has own permission depends upon
what you assign
Using exec() the created process is a sub thread of calling
process. They also share area in memory and so that also
share all permission and resources.
space in memory and also has own permission depends upon
what you assign
Using exec() the created process is a sub thread of calling
process. They also share area in memory and so that also
share all permission and resources.