These two methods seem to be extensively used inside linux kernel code. I know the foundations of branch prediction, but I would like to know how these two functions affect the operation of if() statements. Also do they work at the level of CPU instruction pipeline? or is it at a much higher level of abstraction at kernel code level?  Being a starter to linux kernel I would be deeply interested in knowing the internal workings of these two methods. Thanks!
54115
I've been digging through some parts of the Linux kernel, and found calls like this:  if (unlikely(fd &lt; 0)) {     /* Do something */ }   or  if (likely(!err)) {     /* Do something */ }   I've found the definition of them:  #define likely(x)       __builtin_expect((x),1) #define unlikely(x)     __builtin_expect((x),0)   I know that they are for optimization, but how do they work? And how much performance/size decrease can be expected from using them? And is it worth the hassle (and losing the portability probably) at least in bottleneck code (in userspace, of course).
88826
I often come across interesting Linux commands that make me wonder; what are these commands actually doing?  Yes, they might be 'force-removing dependencies', 'installing programs' and doing lots of other stuff, but I'd like to know how they're doing it.  Looking into the source code seems the right thing to do then, but where am I supposed to get it from?  I suppose they'll be written in C?  EDIT: I'm not talking about packages installed using apt-get. I'm looking for the source code of linux/unix commands.
97648
Almost constantly, I use kernels from the , or kernels I have compiled myself, using the Ubuntu kernel configuration.  The problem is when I am using the stock kernel it seems to default to using predictable network interface names (i.e. "p4p1"), but when I use any alternate kernel it seems to default to using the old method (i.e. "eth0").  While not really relevant to this question, I had a hard disk failure on my test computer and am doing a new install of Ubuntu Server 14.04.2.  I have not been able to determine what is the difference between the kernels. I suspect a kernel configuration parameter, but have been unable to identify which one.  My question: How can I make predictable network interface names work consistently across all kernels?  Additional notes: Somewhere I saw to disable predictable network interface names to add this to grub:  GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0 biosdevname=0"   so, I thought the opposite might help:  GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=1 biosdevname=1"   but it made no difference. Actually, I can never get the non-stock kernel to use biosdevname, no matter the setting. And I can never get the stock kernel to generate a /etc/udev/rules.d/70-persistent-net.rules file (even though, that is not what I want), no matter the setting of net.ifnames. If I have net.ifnames=1, then at least the non-stock kernel doesn't generate an incorrect /etc/udev/rules.d/70-persistent-net.rules file.  Excerpts from /var/log/udev: stock kernel:  KERNEL[9.216730] add      /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/p4p1 (net) ACTION=add DEVPATH=/devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/p4p1 IFINDEX=2 INTERFACE=p4p1 SEQNUM=1945 SUBSYSTEM=net ... UDEV  [9.241073] add      /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/p4p1 (net) ACTION=add DEVPATH=/devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/p4p1 ID_BUS=pci ID_MODEL_FROM_DATABASE=P8P67 and other motherboards ID_MODEL_ID=0x8168 ID_NET_NAME_MAC=enxf46d04652d8e ID_NET_NAME_PATH=enp3s0 ID_OUI_FROM_DATABASE=ASUSTek COMPUTER INC. ID_PCI_CLASS_FROM_DATABASE=Network controller ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller ID_VENDOR_FROM_DATABASE=Realtek Semiconductor Co., Ltd. ID_VENDOR_ID=0x10ec IFINDEX=2 INTERFACE=p4p1   From Ubuntu PPA kernel 4.1RC5:  KERNEL[10.772566] add      /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/eth0 (net) ACTION=add DEVPATH=/devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/eth0 IFINDEX=2 INTERFACE=eth0 SEQNUM=1962 SUBSYSTEM=net ... UDEV  [11.185866] add      /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/eth0 (net) ACTION=add DEVPATH=/devices/pci0000:00/0000:00:1c.4/0000:03:00.0/net/eth0 ID_BUS=pci ID_MODEL_FROM_DATABASE=P8P67 and other motherboards ID_MODEL_ID=0x8168 ID_NET_NAME_MAC=enxf46d04652d8e ID_NET_NAME_PATH=enp3s0 ID_OUI_FROM_DATABASE=ASUSTek COMPUTER INC. ID_PCI_CLASS_FROM_DATABASE=Network controller ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller ID_VENDOR_FROM_DATABASE=Realtek Semiconductor Co., Ltd. ID_VENDOR_ID=0x10ec IFINDEX=2 INTERFACE=eth0 SEQNUM=1962 SUBSYSTEM=net USEC_INITIALIZED=3227   Note: I have temporarily moved past this issue by allowing a /etc/udev/rules.d/70-persistent-net.rules file to be created, and then editing it for proper device names. Ultimately, I would like to get rid of the file.
67466
What is the difference between a "Non-preemptive", "Preemptive" and "Selective Preemptive" Kernel?    Hope someone can shed some light into this.
64883
What does the C value for LC_ALL do in Unix-like systems?   I know that it forces the same locale for all aspects but what does C do?
7945
What is the difference between &gt;&gt; and &gt;&gt;&gt; in verilog/system verilog? I know that == tests for only 1 and 0, while === tests for 1, 0, X, Z. So how is that similar to the shift operator?
46689
I'm reading source code of the linux tool . They use the read() function there. Is there a difference to the standard C fread() function? (I'm not counting the arguments as a difference.)
1970
I have been studying the Linux kernel behaviour for quite some time now, and it's always been clear to me that:     When a process dies, all its children are given back to the init process (PID 1) until they eventually die.   However, recently, someone with much more experience than me with the kernel told me that:     When a process exits, all its children also die (unless you use NOHUP in which case they get back to init).   Now, even though I don't believe this, I still wrote a simple program to make sure of it. I know I should not rely on time (sleep) for tests since it all depends on process scheduling, yet for this simple case, I think that's fairly enough.  int main(void){     printf("Father process spawned (%d).\n", getpid());     sleep(5);      if(fork() == 0){         printf("Child process spawned (%d =&gt; %d).\n", getppid(), getpid());         sleep(15);         printf("Child process exiting (%d =&gt; %d).\n", getppid(), getpid());         exit(0);     }      sleep(5);     printf(stdout, "Father process exiting (%d).\n", getpid());     return EXIT_SUCCESS; }   Here is the program's output, with the associated ps result every time printf talks:  $ ./test &amp; Father process spawned (435).  $ ps -ef | grep test myuser    435    392   tty1    ./test  Child process spawned (435 =&gt; 436).  $ ps -ef | grep test myuser    435    392   tty1    ./test myuser    436    435   tty1    ./test  Father process exiting (435).  $ ps -ef | grep test myuser    436    1     tty1    ./test  Child process exiting (436).   Now, as you can see, this behaves quite as I would have expected it to. The orphan process (436) is given back to init (1) until it dies.  However, is there any UNIX-based system on which this behaviour does not apply by default? Is there any system on which the death of a process immediately triggers the death of all its children?
81821
In the  library, they are overloading the () operator.  Is this a convention in C++? For callbacks, etc.?  I have seen this in code of a co-worker (who happens to be a big Boost fan). Of all the Boost goodness out there, this has only led to confusion for me.  Any insight as to the reason for this overload?
9812
How should I run another program from within my C program? I need to be able to write data into STDIN of the launched program (and maybe read from it's STDOUT)  I am not sure if this is a standard C function. I need the solution that should work under Linux.
4270
Just looking for the difference between   2&gt;&amp;- 2&gt;/dev/null |&amp; &amp;&gt;/dev/null &gt;/dev/null 2&gt;&amp;1   and their portability with non-Bourne shells like tcsh, mksh, etc.
9454
How do I implement some logic that will allow me to reproduce on Windows the functionality that I have on Linux with the fork() system call, using Python?  I'm specifically trying to execute a method on the SAPI Com component, while continuing the other logic in the main thread without blocking or waiting.
95746
I read somewhere once that the modulus operator is inefficient on small embedded devices like 8 bit micro-controllers that do not have integer division instruction. Perhaps someone can confirm this but I thought the difference is 5-10 time slower than with an integer division operation.  Is there another way to do this other than keeping a counter variable and manually overflowing to 0 at the mod point?  const int FIZZ = 6; for(int x = 0; x &lt; MAXCOUNT; x++) {     if(!(x % FIZZ)) print("Fizz\n"); // slow on some systems }   vs:  The way I am currently doing it:  const int FIZZ = 6; int fizzcount = 1; for(int x = 1; x &lt; MAXCOUNT; x++) {     if(fizzcount &gt;= FIZZ)      {         print("Fizz\n");         fizzcount = 0;     } }
38239
Presuming that your C++ compiler supports them, is there any particular reason not to use __FILE__, __LINE__ and __FUNCTION__ for logging and debugging purposes?  I'm primarily concerned with giving the user misleading data—for example, reporting the incorrect line number or function as a result of optimization—or taking a performance hit as a result.  Basically, can I trust __FILE__, __LINE__ and __FUNCTION__ to always do the right thing?
42676
I was wondering if there is something like an interpreter for C.  That is, in a Linux terminal I can type in "python" and then code in that interpreter.  (I'm not sure interpreter the right word).  This is really helpful for testing different things out and I'm curious if something similar exists for C.  Though I doubt it.  The only thing I can think of that would do it would be the C shell...
117410
In Linux environment, when getting "glibc detected *** free(): invalid pointer" errors, how do I identify which line of code is causing it?  Is there a way to force an abort? I recall there being an ENV var to control this?  How to set a breakpoint in gdb for the glibc error?
118935
Linux doesn't actually distinguish between processes and threads, and implements both as a data structure task_struct.  So what does Linux provide to some programs for them to tell threads of a process  from its child processes? For example,   Thanks.