There's a shell script floating around the Internet that looks like this:   :(){ :|: & };:   Basically this shell script just creates a function that calls itself, leading to infinite recursion.  Apparently this is a fork bomb and it will keep going until it uses up resources and crashes your system.  My question is, wouldn't this script cause a stack overflow and cause the shell to segfault before it consumes all the system's resources?  How does this work exactly?
105151
WARNING DO NOT ATTEMPT TO RUN THIS ON A PRODUCTION MACHINE   In reading the  I generally follow what's going on with the following code:  :(){ :|:&amp; };:   excerpt of description     The following fork bomb was presented as art in 2002;   its exact origin is unknown, but it existed on Usenet prior to 2002.   The bomb is executed by pasting the following 13 characters into a    shell such as  or . It operates by defining   a function called ':', which calls itself twice, once in the   foreground and once in the background.   However the last bit isn't entirely clear to me. I see the function definition:  :(){ ... }   But what else is going on?  Also do other shells such as ksh, csh, and tcsh also suffer the same fate of being able to construct something similar?
67708
I have a unix installation that's supposed to be usable both as a chroot and as a standalone system. If it's running as a chroot, I don't want to run any service (cron, inetd, and so on), because they would conflict with the host system or be redundant.  How do I write a shell script that behaves differently depending on whether it's running in a chroot? My immediate need is a modern Linux system, with /proc mounted in the chroot, and the script is running as root, but more portable answers are welcome as well. (See  for the case of Linux without /proc.)  More generally, suggestions that work for other containment methods would be interesting. The practical question is, is this system supposed to be running any services? (The answer being no in a chroot, and yes in a full-fledged virtual machines; I don't know about intermediate cases such as jails or containers.)
36270
Is there a script or a way in linux that when I try to execute a shell script/process, if the same is running, it will prompt that same is running and will exit otherwise it will continue.
112227
Is there a standard Unix command that does something similar to my example below  $ &lt;cmd here&gt; 56 $ echo Return code was $? Return code was 56 $   &lt;cmd here&gt; should be something that can be fork-execed and leaves 56 as the exit code when the process exits. The exit and return shell builtins are unsuitable for what I'm looking for because they affect the invoking shell itself by exiting out of it. &lt;some cmd&gt; should be something that I can execute in non-shell contexts - e.g., invoking from a Python script with subprocess.  E.g., /usr/bin/false always exits immediately with return code 1, but I'd like to control exactly what that return code is. I could achieve the same results by writing my own wrapper script  $ cat my-wrapper-script.sh # i.e., &lt;some cmd&gt; = ./my-wrapper-script.sh #!/usr/bin/bash exit $1 $ ./my-wrapper-script.sh 56 $ echo $? 56   but I'm hoping there happens to exist a standard Unix command that can do this for me.
83496
How does gcc implement stack unrolling for C++ exceptions on linux?  In particular, how does it know which destructors to call when unrolling a frame (i.e., what kind of information is stored and where is it stored)?
100567
This is from . It's about executing a Perl script.     Finally, if you are unfortunate enough to be on an ancient Unix system   that doesn’t support the magic #! line, or if the path to your   interpreter is longer than 32 characters (a built-in limit on many   systems), you may be able to work around it like this:   #!/bin/sh -- # perl, to stop looping eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0;   Can you explain step by step what's going on here? I'm trying to make it work or encompass, but to no avail.  At execution of just the above, I'm getting this:  /bin/sh: 0: Illegal option --
104056
I'm trying some things with my shell. This includes the following command:  kill $$  My expectation was that the shell would log me out and terminate itself. But instead the bash persists without change.   Any idea why?  I ran this command on different environments (archlinux, debian). The behavior was always the same.
46113
I am new to shell scripts and many books have written that use #!(sha-bang) line in starting of the script to invoke the interpreter .And this will invoke a new shell for script and do the interpretation line by line.But one of my basic script is still running without the magic line.  so my questions are:   from where did my basic script get the interpreter. how did the script manages to locate the interpreter.   now let me tell you about my basic script it just contains the following line:  echo "basic script without the magic lines"
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?
73904
When is it a good idea to use ?  I sometimes see this in code samples of PHP. Does this handle DOS/Mac/Unix endline issues?
26696
In Program 1 Hello world gets printed just once, but when I remove  \n and run it (Program 2), the output gets printed 8 times. Can someone please explain me the significance of \n here and how it affects the fork()?  Program 1   #include &lt;sys/types.h&gt; #include &lt;unistd.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;  int main() {     printf("hello world...\n");     fork();     fork();     fork(); }   Output 1:  hello world...    Program  2  #include &lt;sys/types.h&gt; #include &lt;unistd.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;  int main() {     printf("hello world...");     fork();     fork();     fork(); }   Output 2:  hello world... hello world...hello world...hello world...hello world...hello world...hello world...hello world...
711
Does anything symbolic happen in chaining bash commands via a pipe or is it all compute-pass-compute-pass?   For example in head t.txt -n 5 | tail -n 2, is head t.txt -n 5 getting computed and then tail -n 2 executes over it. Or first there is some abstraction to tell the shell that lines 3 to 5 are to be read? It might not make a difference in this example, but I guess can in other scenarios.
42820
When going through one shell script, I saw the term "$?". What is the significance of this term?
96825
Say I have the following script:  #!/bin/bash for i in $(seq 1000) do     cp /etc/passwd tmp     cat tmp | head -1 | head -1 | head -1 &gt; tmp  #this is the key line     cat tmp done   On the key line, I read and write the same file tmp which sometimes fails.  (I read it is because of race conditions because the processes in the pipeline are executed in parallel, which I do not understand why - each head needs to take the data from the previous one, doesn't it? This is NOT my main question, but you can answer it as well.)  When I run the script, it outputs about 200 lines. Is there any way I can force this script to output always 0 lines (so the I/O redirection to tmp is always prepared first and so the data is always destroyed)? To be clear, I mean changing the system settings, not this script.  Thanks for your ideas.
99622
Why was Stack Overflow forked into  ? I don't understand this. I think it is stupid ;-)
11663
I am looking for a way to clean up the mess when my top-level script exits.  Especially if I want to use set -e, I wish the background process would die when the script exits.
1982
The following code is generating a stack overflow error for me  int main(int argc, char* argv[]) {     int sieve[2000000];     return 0; }   How do I get around this? I am using Turbo C++ but would like to keep my code in C  EDIT:  Thanks for the advice.  The code above was only for example, I actually declare the array in a function and not in sub main.  Also, I needed the array to be initialized to zeros, so when I googled malloc, I discovered that calloc was perfect for my purposes.  Malloc/calloc also has the advantage over allocating on the stack of allowing me to declare the size using a variable.