Questions tagged [exec]
The exec() family of functions replaces the current process image with a new process image, retaining the pid and pipes of the old process. This tag is also used for the shell built-in which can be used to replace the current shell with a program or various redirection-related stuff.
287 questions
6
votes
1
answer
199
views
pam_mount results not available in pam_exec
How can a pam_exec script access mounts performed by pam_mount?
I have a working auth optional pam_mount.so PAM configuration such that the device is not mounted before entering the passphrase (tested ...
0
votes
3
answers
193
views
In Linux how do I wrap an executable in a script so arguments and output work as the original executable expects?
Say I have an executable 'foo' and it is typically called with arguments, for example "foo -a1 v1".
And 'foo' happens to be a resource hog, so I want to run something like "nice -n 10 ...
4
votes
2
answers
2k
views
'exec fish' at the very bottom of my '.zshrc' - is it possible to bypass it?
I prefer to use the fish shell on macOS most of the time, but refrain to make it the login shell, because I think sometimes it may cause problems.
So, I simply added exec fish at the very bottom of my ...
2
votes
0
answers
60
views
In the context of {ARG_MAX}, how robust is `find . -exec sh -c 'exec tool "$@" extra-arg' find-sh {} +`?
Suppose I want to do this:
find . -exec tool {} extra-arg +
It doesn't work and I know why: -exec … {} + does not allow extra-arg(s) between {} and +. So be it. It seems I can inject the extra-arg by ...
2
votes
1
answer
131
views
Why does exec in bash script run by cron not preserve $PATH?
I have the following cron job setup on Debian 12:
/etc/cron.d/jonathan-test:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
* * * * * jonathan /home/jonathan/test1....
0
votes
1
answer
58
views
Are reads of /proc/pid/environ atomic in Linux 6.x (e.g: 6.1.99)?
When a process execs, looking at kernel code for environ_read(), it seems that if the mm_struct doesn't yet exist / is null or the env_end member of that mm_struct is null, environ_read() will return ...
0
votes
0
answers
87
views
Understanding AFL behaviour for fork and execv; Why `/proc/<pid>/maps` does not show the loaded binary
TL;DR Why process map in /proc/<pid>/maps does not show where the executed binary is loaded?
I am trying to do some post-mortem analysis of the fuzzed program once it finishes.
Basically what I ...
2
votes
1
answer
290
views
How to pass a parameter to a command that's being executed by exec in bash?
I'm trying to start a subprocess with a unique process name from a bash script. This works:
bash -c "exec -a MyUniqueProcessName './start_service' &"
but my problem is that I want to ...
4
votes
1
answer
246
views
POSIX Shell: `exec` with changed arg0
I want to exec a program and control it's arguments including arg0 and environment. Using C I could go for execve. Can I do this in POSIX shell?
0
votes
1
answer
338
views
How to perform strace on shell without changing your current shell?
I use strace to trace the behavior of a bash process. The purpose is to find out the order bash loads its configuration files.
I am running the following command under zsh:
strace -e openat bash
...
16
votes
1
answer
1k
views
Is the behavior of bash -c "<single command>" documented?
It's quite known that when running bash -c "COMMAND" (at least in the common versions in Linux) when there's a single command without any metacharacter (except for space, tab or newline), ...
0
votes
2
answers
123
views
Creating an option for 'exec > >(tee -ia $OUT)' to skip stdout
I'm trying to modify a script that uses the following:
# first portion of script
# ...
exec > >(tee -ia $OUT)
# ...
# second portion of script
The problem I have with this script is that it ...
0
votes
1
answer
100
views
How to execute a subshell directly
I have this:
timeout 25 bash -c '
for i in {1..9}; do
if read line < "$my_fifo"; then
if test "$line" != "0"; then
exit 0;
...
3
votes
1
answer
274
views
How to stop redirection via exec
I want to redirect some output of a script to a file.
REDIRECT_FILE="foo.txt"
echo to console
# starting redirect
exec > $REDIRECT_FILE
echo to file
echo ...
echo ...
# stop redirect
...
1
vote
0
answers
92
views
How to regain script interactivity when `... | bash` best practices?
Let's say we have a simple script named question:
#!/bin/bash
read -rp "What's your name?" ans
echo "Your name is $ans"
Let's use cat for our example
cat question | bash
We ...