fork

Writing a simple, intelligible fork bomb in bash? [closed]

99封情书 提交于 2019-12-11 09:06:20
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 8 years ago . How can I do this? I just wish to write something like while(true) { fork() } Is this possible in bash ? I don't want it for religious reasons, just to

How to loop through stdin & pipe output to a child execl command in C?

≡放荡痞女 提交于 2019-12-11 09:02:16
问题 I have been trying to figure out how to loop through stdin from a file, then send it to a child process who sorts int using execl(). The code below works in that it takes the file & sorts the lines, but I am not seeing the "end of sentence" debug string I have added. Somehow this part of the code is being bypassed. I could use some help understanding the flow of data as it comes in from the file, then gets printed out to the screen. int main(int argc, char *argv[]) { pid_t p; int status; int

Two redirect in program

纵饮孤独 提交于 2019-12-11 08:49:51
问题 I try write a command interpreter in C. I must create dwo and three redirects (e.g. ls | grep ^d | wc -l and ls -ps | grep / | pr -3 | more ) I have code to operate one redirects if(k==1) { int pfds[2]; pipe(pfds); child_pid = fork(); if(child_pid==0) { close(1); dup(pfds[1]); close(pfds[0]); execlp(arg1[0], *arg1, NULL); } else { close(0); dup(pfds[0]); close(pfds[1]); execlp(arg2[0], *arg2, NULL); } } My question is how make two and three redirects using pipe and fork ? I try do this using

non-blocking system call in c++ program using fork

笑着哭i 提交于 2019-12-11 08:25:38
问题 Based on this SO post, and this example, I expect that, when I use fork(), will allow me executing system/execvp in non-blocking manner. However, when I try to issue a long-running child process in a fork block in the above mentioned example code, the control does not return to parent block, till the child has finished. Can you tell a method, how I should design the code to allow non-blocking calls to system, in C/C++ code. Also, I plan to write a program, where more than one chidren are

Forking And Piping C++ Strange Ouput

喜夏-厌秋 提交于 2019-12-11 08:17:14
问题 I am to write an assignment that takes 2 commands and their arguments (up to 5) and it will pipe the output of one to the other. It will then loop, again asking for two commands until quit is entered. The problem I am having is that after entering values on the second loop, weird things happen, such as outputting "Enter Command 1" right after entering the second command (both appear on the same line). I also noticed that entering ls -l and then cat works for example, but entering ls -l then

implementing pipe and redirection together in C

跟風遠走 提交于 2019-12-11 07:45:36
问题 I am working on making a minimal shell in C. I understand how pipe and redirection work. I have two programs, one program that handles redirection, for example ls -l > outputfile . I have another program that handles one pipe, for example, ls - l | wc . The main trouble I am having is to put them together. Basically, I want to be able to implement both pipe and redirection in one program. Below is part of the code for pipe. pipe(p); if (fork() == 0) { dup2(p[1], 1); close(p[0]); execvp

Dynamically name processes

人走茶凉 提交于 2019-12-11 07:45:12
问题 Is it possible for a program to create dynamically name processes that it starts? Consider the famous fork bomb code: :(){ :|:& };: or import os while os.fork() or True: os.fork() Would it be possible to let it generate a new random process name every time that it executes? Which would make it a lot harder to get rid of. It doesn't necessarily have to be in perl or python, I'd love to see examples in other languages too. 回答1: It is usually possible to set the process name, but this capability

Inquiry- Loops in Relation to Parent/Child/Fork/Pids

假装没事ソ 提交于 2019-12-11 07:38:21
问题 I am attempting to learn the functionality of parents, children and pipes in perl. My goal is to create a single pipe (not bidirectional) that reads from the command line, and prints it through a pipe. Referencing the pids many many times. The code so far: #!/usr/bin/perl -w use warnings; use strict; pipe(READPIPE, WRITEPIPE); WRITEPIPE->autoflush(1); STDOUT->autoflush(1); my $parentpid = $$; my $childpid = fork() // die "Fork Failed $!\n"; # This is the parent if ($childpid) { &parent (

Having issues with pipe, fork, dup2

非 Y 不嫁゛ 提交于 2019-12-11 07:36:50
问题 I am using pipes, fork , dup2 to implement “ls | more” or “ls | sort” etc. I am just not able to understand the issue here. When I run my program, I get this error: ./a.out Missing filename ("less --help" for help) Why am I getting "less" ?? What is wrong with this code ? If I change “more” to “ls” again, it works fine. I mean, its like doing ls | ls. #define STDIN 0 #define STDOUT 1 int main() { int fd[2]; int pid; char *lschar[20]={"ls",NULL}; char *morechar[20]={"more",NULL}; pid = fork();

Using a Pipe to Write and Read Array of Int

核能气质少年 提交于 2019-12-11 06:56:44
问题 I'm trying to make a simple program using the pipe. The program must request an array of integers in the parent, and send it to the child, which must sort the array and send it back to the parent. The problem is that I'm not sure how I read the array values in the child, after sending through the pipe. follow my code: #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main() { int fd[2]; pid_t pid; /* Verifica se ocorreu erro (-1) ao criar o PIPE */ if(pipe(fd) == -1){ perror(