Linux Socket Programming

  Home  Operating System Linux  Linux Socket Programming


“Linux System Calls frequently Asked Questions by expert members with experience in Linux System Calls. These interview questions and answers on Linux System Calls will help you strengthen your technical skills, prepare for the interviews and quickly revise the concepts. So get preparation for the Linux System Calls job interview”



6 Linux Socket Programming Questions And Answers

1⟩ 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.

 207 views

2⟩ 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.

 141 views

3⟩ 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("%sn",inet_ntoa(client.sin_addr));

printf("%dn",(int) ntohs(client.sin_port));

 183 views

4⟩ 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

 141 views

6⟩ 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.

 173 views