minishell | 42 - Rewrite a simple shell | Command Line Interface library
kandi X-RAY | minishell Summary
kandi X-RAY | minishell Summary
42 project, recoding our own little bash. A program capable of parsing a prompt and launching executables with arguments, along with a few built-in functions.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of minishell
minishell Key Features
minishell Examples and Code Snippets
Community Discussions
Trending Discussions on minishell
QUESTION
I am writing my version of minishell and trying to implement heredoc (<<
) in C. I decided to use tmpfile - first I write data from stdin
to tmpfile until I reach a delimiter, then I change program's stdin to the fd
of the tmpfile with dup2
and, then, try to execute cat
command with execve
.
I tried to simplify the program and include all relevant functions below:
...ANSWER
Answered 2021-Dec-05 at 22:11Improve your logging. I imagine your output is correct, but looking like
QUESTION
I'm trying to implement a minishell which must be able to pipe commands.
Initially, I was executing the processes sequentially, that is, I was waiting for n
th a process to terminate before starting the n + 1
th process (this is a minimal reproducible example which executes ls | wc -l
):
ANSWER
Answered 2021-Aug-24 at 05:43Thanks for the insightful comments.
If I add close(pipefd[0])
and close(pipefd[1])
immediately after dup2()
s, the issue gets solved.
I thought that it was enough to close the pipe only from the main, shell process, but it turned out that all occurrences of fds have to be closed, including the ones inside children who inherit a copy.
The reason I got confused is the fact that the first piece of code worked. Now I realize that there, I was waiting for the first (ls
) process to exit, so when it exits, its copy of the write-end gets destroyed, and I close the last copy of it in the main process. Then wc
doesn't inherit any.
So now in my shell, during execution inside a child, after dup2()
ing the descriptors, I close each and every descriptor created by pipe()
, and it works.
QUESTION
Good day,
I'm writing my own shell in C for my school which has to resemble bash
as closely as possible.
I have to handle signals such as Ctrl-\ and Ctrl-C as bash
does; for this reason I'm allowed to use signal
function. It works fine, but the thing is whenever a Ctrl-C signal is caught (starting from the second catch), a ^C
is printed.
On the net, I've found a workaround suggesting printing "\b \b\b \b\nminishell$ "
whenever a Ctrl-C is caught, which will devour the two symbols. The thing is, since at the very first time ^C
is not printed, the print devours two symbols of my prompting, making it just minishell
instead of minishell$
, with the cursor incorrectly displayed.
Now I've come up with another workaround for this workaround which is to declare a static boolean to not print the baskspaces at the very first call. This doesn't help in case of Ctrl-\ though; Ctrl-\ proceeds to move my cursor to right when I attempt to write the two whitespaces that must replace the ^\
.
I don't like these workarounds and would like to know whether there is a way to instruct the terminal not to output this stuff? I'm allowed to use tgetent
, tgetflag
, tgetnum
, tgetstr
, tgoto
, tputs
, tcsetattr
, tcgetattr
, have read their man pages but nothing seems to be helpful.
ANSWER
Answered 2021-Jul-31 at 13:18Wouldn't this work?
QUESTION
I am having the following error when I run Valgrind, I tried to free all the used functions, but still have the same error message
...ANSWER
Answered 2021-Apr-11 at 00:23The line of Valgrind output that should concern you is this specific one:
QUESTION
i found a file with the code given below in my public_html.it is a wordpress website.is it a malware or backdoor?Can i identify how this code was injected from this file?
...ANSWER
Answered 2020-Aug-21 at 18:01As stated in the comments, the line is malware. It's possible there are other files on your server affected as well, so I would scan the date modified on them to see if any have been changed around the same time that file was created. This becomes much easier if you have SSH access and are able to use find.
Identifying the source of the attack is trickier. I would start by looking at the file you pointed out - which user created it? The server itself or an FTP user? Then I would talk to the web host about it.
Finally, I would change all admin WordPress passwords to be on the safe side. Might want to change your cpanel user's password as well.
QUESTION
I'm writing my minishell and I can't understand why execve doesn't work when calling pid_2 ?
My main task is to implement env | grep LANG
ANSWER
Answered 2020-Aug-11 at 09:19There are three issues in your code:
execve()
doesn't search for the command in$PATH
so generally it won't find neitherenv
norgrep
. Useexecvp()
instead.- You should call
pipe()
before the firstfork()
to prevent another pipe to be created and used by the child process - as @KamilCuk has pointed out: in the first child process, you should
dup2()
stdout instead of stdin
Fixing these bugs lead to this working code
QUESTION
I'm currently running a mini shell with a C++ program, and when the user types "exit", the main_func()
returns -1
. At that point, the print statement (in the child process) will print, which is followed by exit
, yet the loop (in the parent process) continues to run. Only time it'll actually end is if I use the kill
shell command, but this does not end my program cleanly.
Kill function that would end my program
...ANSWER
Answered 2020-Jun-30 at 05:41Fundamentally, fork()
creates a separate process (child). Most of the actions taken in the child process are not reflected in the parent. exit()
is one such action. After calling exit()
, the child is terminated, and the parent remains unaffected (well, SIGCHLD is passed to the parent who is mostly ignored).
So to notify the parent of the exit()
event (main_func()
returning -1), you need to adopt some extra mechanism. One way to do this is, signaling the parent. But to signal the parent, parent PID is required. Unlike in the case of the parent, fork()
won't return the parent PID in the child. You need to call getppid()
for obtaining the parent PID. Following code does the same:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install minishell
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page