:(){ :|:& };: Forkbomb? [duplicate] - linux

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
The following bash command will spawn processes to kernel death. Can you explain the syntax?
:(){ :|:& };:
running this fork() unlimited .. Can one please explain this bash script ?

You define a function called :. Inside this function you call this function twice (:|:) and then you send that process to the background (&). Then you finally call it at the end.
Because of the recursive nature, you'll keep forking. Since there is no base case, the recursion will never end.

Related

Doubts about stopping command line process [duplicate]

This question already has answers here:
How to abort execution in GHCI?
(3 answers)
Closed 9 months ago.
I found that when I execute
a = 1:a
a
in command line, I can press Ctrl+c to stop the infinite process.
But Ctrl+c fails to stop the process when I execute
length a
However, Ctrl+c works well when I execute
length [0..]
Why does Ctrl+c sometimes fail to stop the process? Is there any ways to stop the process when Ctrl+c is invalid?
Under Windows, there is a bug where, after pressing Ctrl + C, GHCI appears to exit but still seems to run in the background. The only documentation I could find is https://gitlab.haskell.org/ghc/ghc/-/issues/14150 but I've experienced it myself multiple times using version 9.2.1.when working with infinite data structures like infinite lists [1..].

Is there anyway to find the PID of parent process without using getppid? [duplicate]

This question already has answers here:
Programmatically get parent pid of another process?
(7 answers)
Closed 5 months ago.
I know that the PCB is a data structure which includes parent
process id(pPID), process id(PID), pointers, and etc. Is there anyway
to find the PID of parent process without using getppid function?
The fields of /proc/self/stat (as documented in proc(5)) include PPID. Take care in parsing as comm may contain spaces and other unusual characters.
(But I second #JohnZwinck's comment. Why?)

Execute a command when a bash script is not responding? [duplicate]

This question already has answers here:
How to kill a child process after a given timeout in Bash?
(9 answers)
simple timeout on I/O for command for linux
(3 answers)
Closed 5 years ago.
Here's my situation: I've made a script in a while loop, but sometimes (say after 20-30 loops) it stops unexpectedly.
I tried to debug it but I couldn't.
I noticed that it stops while executing a command, and it just doesn't do anything when it stops. Now I was thinking: is there a way to tell to another script when the first script stops and it doesn't execute any command in, say 120 seconds? Maybe by constantly observing the output of the first script and when it's giving no output, the second script kills the first one and makes it start again? Sorry for my bad English hope I was clear.

system() call in perl [duplicate]

This question already has answers here:
in perl, how do we detect a segmentation fault in an external command
(2 answers)
Closed 8 years ago.
I want to make a system() call in a perl script and, because I want to redirect stdin and stdout, I think I need to pass a single string to system() and let the shell interpret the metacharacters. However, I do not seem to be able to correctly detect when the program called via system() segfaults.
The perl system() man page at http://perldoc.perl.org/functions/system.html cautions "When system's arguments are executed indirectly by the shell, results and return codes are subject to its quirks." Should I be concerned about this?
My code for testing the return value of system() is pretty much identical to the example given on the same man page (just above the warning I mention) but in retrospect that appears to be for calling system() with a LIST.
So, I tihnk my core issue is, how do I detect how a program terminated that was called in a shell from perl's system(). Apologies if this is a repeat question but I cannot find it addressed anywhere before. FWIW I'm running the script on a Fedora distro of linux.
Many thank.
I would suggest you have a look at IPC::Open2 and IPC::Open3
What you are trying to do is a bit too complicated for system which is more or less geared up to running a command, and then capturing output.
IPC::Open2 allows you to open an exec pipe to a process, and attach your own filehandles to STDIN and STDOUT, meaning you can do bidirectional communication. (Open3 also allows STDERR).
Catching signals and errors on your attached process is a bit more complicated - the only thing you're fairly sure to get is a return code. With system, $? should be set automatically, but with IPC::Open[23] you may need to use waitpid to catch the return code.

What does "$$" means in shell script? [duplicate]

This question already has answers here:
What does $$ mean in the shell?
(12 answers)
Closed 8 years ago.
I came across "$$" expression in shell script, something like this
TFILE=$$
Can anyone tell me its meaning?
$$ means the process ID of the currently-running process.
It's the process id of the current process - see a previous question on StackOverflow for details: What does $$ mean in the shell?
$$ is the process id of the currently running process in UNIX.
mostly it is used with naming of logfiles aor temp files, such that there is no conflict of file names while multiple instances of the same scripts are running.
echo "$$" prints PID of current running process.

Resources