I’m new to C and socket programming, just a question on getaddrinfo function. The function prototype of getaddrinfo is: and getaddrinfo returns a result that points to a linked list of addrinfo structures, each of which points to a socket address structure that corresponds to host and service. Below is my questions: Q1-Why it needs to return a result that
Tag: c++
recv() skipping UDP packets
I wrote simple program to handle incoming UDP packets. I send 60000 UDP packets to and this programm is losing packets. Bandwith about 60-70 Mbit/s. If I wun tcpdump in parallel, then I see that all packages are received by the kernel. Also I tried recvmsg and recvmmsg with same result. Program source code: Answer The problem was solved. I
Fork how many processes created confused
Say i have the following program So now what we have: Fork #1 creates an additional processes. so now we have two processes. Fork #2 is executed by two processes, creating two processes, for a total of four. My confusion is after the first fork we will have two processes P1(parent) and C1 (child). each process will execute the second
different ways to ignore a signal?
Im’ new to Linux and signal handling. the signal function prototype is below is my questions: Q1-if I want to ignore SIGINT signal, then I just need to simply code as: signal(SIGINT, SIG_IGN);, is my understanding corrct? Q2-What if I code as: since my own sigint_handler does nothing, it is pretty much like ignoring the SIGINT, so can I say
Why does read block on a pipe until the write end is closed?
I’m trying to bolster my understanding of things related to fork, exec, dup, and redirecting stdin/stdout/stderr by writing the following popen-type function: Compilation and execution: My question is about the read() – I don’t quite grok why does the read() is seemingly block until the child process has completed (thereby closing its end of the pipe)? Is it coincidence? You
not all malloc’ed memory is “heap” and each block is not contiguous in virtual memory?
It seems that malloc calls mmap internally as : so malloc passes NULL as the first argument for mmap as starting address, so the kernel will choose a suitable virtual address for the mapping, which means malloc will not necessarily create a mapping in the heap area(indicated by brk pointer). If this is true, that means there will be a
io.h not found CLion in Ubuntu 20.04
I am trying to run a c++ code however, io.h is not found. It is shown as Additionally, I am getting a bunch of weird problems (for a code that is rather > 16 years old): or or or or or or I wonder if these are related to io.h not being found. I have CLion 2020.2.3 and Answer Add
Meaning of adding 1 on socket file descriptor in select function when using linux socket
What is the meaning of adding 1 on socket file descriptor when using in select function? I create socket file descriptor like below, and use it in select function like below, What is the meaning of +1 in select function? It even does not work when I remove the calculation adding the value. Thanks in advance. Answer RTFM! The first
How do you create a C program that resembles the nl command in Linux?
I am working on a project to create a C program that acts just like the nl command in Linux, with the exceptions; it only accepts limited options, does not accept dashes to denote standard input, and no need for division of documents into logical pages with headers/footers. This is a link to an nl manual page: https://ss64.com/bash/nl.html This is
ld: Final link Failed: Memory exhausted while building Linux kernel 5.8.9
I am trying to compile Linux Kernel 5.8.9 on Ubuntu 16.04 installed on VirtualBox ( specifications: 22 + 3 GB, Memory : 2 GB). After successfully making the .config file using make menuconfig, I compiled it using make. The compilation ran for around 100 minutes and stopped abruptly displaying error memory exhausted. How can I remove this error? Answer As