Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

6
votes
2answers
335 views

Echo to file descriptor overwrites the file?

I am having trouble understanding what is happening when I try to write to a file descriptor? It appears to be overwriting the original contents? Is this expected behaviour? I have replicated this in ...
0
votes
2answers
28 views

Eval and exec with variable substitution

I'd like to execute a statement to start a server. For that I have an environment variable to determine which server is to be started. I was given this command as a starting point: eval "exec ...
-2
votes
0answers
40 views

Does `execve()` set up registers to invoke dynamic linker or the executable to be executed? [migrated]

Understanding the Linux Kernel says execve() calls load_binary() of each linux_binfmt object, and load_binary() Invokes the start_thread( ) macro to modify the values of the User Mode registers ...
0
votes
1answer
52 views

What are differences between `do_execve()` and `_start` copying the command line arguments and environment?

Understanding The Linux Kernel says that execve() calls do_execve( ) which in turn copies the file pathname, command-line arguments, and environment strings into one or more newly allocated page ...
1
vote
1answer
99 views

How does `execve()` call a special start-up routine and the main() function?

When a C program is executed by the kernel—by execve(), where does execve() call a special start-up routine crt0 which is called before the main function is called? where does execve() call ...
0
votes
0answers
35 views

How does `execve()` pass command line arguments to `main()`? [duplicate]

How does execve(path, argv, envp) pass the command-line arguments in argv array and the environment envp array to the main function of the executable file being executed? Does it pass the address ...
2
votes
1answer
62 views

Using exec 3> to keep a named pipe open

The process reading from a named pipe will normally terminate when the process writing to the pipe finishes writing (sends an EOF). In certain situations you may have different processes writing ...
0
votes
2answers
37 views

How to delete directories based on `find` output: ONLY the first result

Based on this question, How to delete directories based on `find` output? I tried to remove only the first folder of result doing: find * -type d | head -n1 | -exec rm -rf {} \; But I receive ...
0
votes
1answer
43 views

Find, grep and then create table

I am trying to find all *.md at ${PWD}, then grep for lines beginning with title: and print it along with the absolute filepath -H and the line number of the pattern match -n, then I try to output the ...
-1
votes
1answer
58 views

Does the Linux kernel support a PARTIAL exec

I was looking at another question (https://stackoverflow.com/q/47845/537980), and saw an answer, about how much set up this other OS had to do, for every Process Create. I got wondering. Would it be ...
3
votes
1answer
53 views

What's the purpose of 1> in exec 1> >(logger -s -t tagname) 2>&1?

I just stumbled over exec 1> >(logger -s -t $(basename $0)) 2>&1 which is used to redirect the output of the current script to the system logger (in case you've never seen this, but are ...
0
votes
2answers
65 views

Question about global environment variables and fork() & exec() [duplicate]

What I'm trying to understand is where does a child process inherit exported variables from it's parent process What I'm trying to understand is where a child process inherits exported environment ...
10
votes
5answers
2k views

Capture exit code of exit command

I have this in a bash script: exit 3; exit_code="$?" if [[ "$exit_code" != "0" ]]; then echo -e "${r2g_magenta}Your r2g process is exiting with code $exit_code.${r2g_no_color}"; exit "$...
0
votes
1answer
88 views

Is `argv [0]` of `execve()` required to be the same as the basename component of the `pathname` argument?

In #include <unistd.h> int execve(const char * pathname , char *const argv [], char *const envp []); argv [0] of execve corresponds to argv[0] in the main function of the new program, and ...
1
vote
1answer
25 views

How to Start a Service in a Specific Directory via Daemontools?

I am using daemontools to start my application. In the run script, I have something like exec taskset -c 2 [absolute path to my application] But the problem is that one of the black box library my ...
0
votes
1answer
77 views

How to use parameter expansion with find -exec {}? [duplicate]

I want to incorporate something like: for f in */*; do mv "$f" "${f%/*}/foo.${f##*.}"; done Into my find x -exec y {} \;-style workflow. The for loop construct & "$f" variable will ...
-1
votes
1answer
77 views

bash - use exec for file descriptors using environment variables

LOCK_FD=200 LOCK_FILE=/tmp/lock-file exec ${LOCK_FD}>${LOCK_FILE} I get an error exec: 200 not found This however works LOCK_FD=200 LOCK_FILE=/tmp/lock-file eval "exec ${LOCK_FD}>${LOCK_FILE}...
2
votes
1answer
87 views

using both trap and exec to redirect output to tee in bash

I have script that reads lines from a file, processes each line. I'd like to be able to do some "post-processing" in a way that even when the script didn't finish reading all lines because I pressed ...
1
vote
1answer
63 views

What happens to the old stack, heap, and (initialized and uninitialized) data segments after execve() call?

Manpage of execve() says execve() executes the program pointed to by filename. This causes the program that is currently being run by the calling process to be replaced with a ...
10
votes
2answers
1k views

Why is vfork() intended to be used when the child process calls exec() or exit() immediately after creation?

Operating System Concepts and APUE say With vfork(), the parent process is suspended, and the child process uses the address space of the parent. Because vfork() does not use copy-on-write, if ...
-1
votes
1answer
124 views

How can I add find exec command into bashrc?

find . -name "*.mov" -exec bash -c 'ffmpeg -i "{}" -c:v libx264 -crf 20 -pix_fmt yuv420p "${0/.mov}.mp4"' {} \; Above command works perfectly when I run it manually but I could not put it within a ...
1
vote
1answer
32 views

Linux find exec - output to a different directory

I'm trying to come up with a short script to edit some csv files. First, I need to replace delimiters, then change encoding to UTF-16. I would like to do this in two steps, saving the results in two ...
0
votes
0answers
36 views

Logging output of scripts called inside another script

Inside bashscript, I am using exec and tee to redirect logs to stdout and a log file in the same time - Unix & Linux Stack Exchange. exec &> >(tee -a "${LogFile}") I am sourcing ...
1
vote
1answer
109 views

execl() is not executing a command without its absolute path

I have C program saved under /usr/sbin/. This program prints "Hello World" every two seconds. I can call/execute this program from any folder. When I write C program with system("a.out"); in it, it'...
1
vote
1answer
60 views

What properties of an unprivileged process are preserved during an `execve` call?

I am teaching an Operating Systems course and trying to wrap my mind around the fork/execve technique for creating new processes. My current understanding is that a fork make a complete copy of the ...
1
vote
1answer
44 views

find - exec to remove directories with a dollar [duplicate]

In maven local repository directories with dollar name - unresolved properties? I have outlined how I ended up with a few dozen directories that have a dollar sign in their filename. I tried to get ...
1
vote
1answer
258 views

fork() and COW behavior after exec()

We understand the COW behavior after a fork (as for example described here) as follows: fork creates a copy of the parent's page table for the child and marks the physical pages read only, so if any ...
2
votes
3answers
299 views

find . * -exec ll {} \; -> with just one result instead of four

I'd like to use find command to search all files in one directory: find . * -exec ll {} \; Result shows four (!) results per file: file123 ./test/file123 file123 test/file123 Is it possible to ...
0
votes
3answers
74 views

What does `exec “$@”` do?

I've been seeing this in a lot of docker-entrypoint.sh scripts recently, and can't find an explanation online. My first thoughts are that it is something to do with signaling but that's a pretty wild ...
1
vote
1answer
211 views

How can I make a specific process exec a given executable with ptrace()?

I am trying to force the init process of an embedded Linux system to exec() my own init program (systemd) so that I can test an external filesystem before writing it to the system's flash (and risk ...
0
votes
1answer
37 views

Why would `read -s` behaves differently than `read` if killed with `ctrl-c`?

Consider this script: #!/bin/bash echo "hi there $(whoami)" [ "`whoami`" = "root" ] || { exec sudo -u root "$0" "$@" echo "this is never called" } read -s -p "enter stuff: " stuff echo "answer:...
0
votes
2answers
137 views

Should exec always be the last line of shell script?

I have a shell script that does the following: export FOO=foo # step 1 /usr/bin/java my-server # step 2 This shell script is launched by a parent program that needs to know the PID of the ...
0
votes
0answers
83 views

AIX kernel internal stats of nmon: fork vs exec

Why the values of fork and exec stats shown on the kernel internal stats of nmon utility in AIX systems (k option) are so different? Usually the shown fork value is greater than the exec value, ...
-1
votes
2answers
201 views

Unable to set LS_COLORS in bash using script

I am trying to set the LS_COLORS environment variable using a launcher script. However this variable is not being set. Steps Downloaded LS_COLORS to ~/.dircolors Added TERM=xterm-newTerminalEmulator ...
-1
votes
0answers
234 views

find with -exec option is not working

I'm trying to use find command (Solaris 11) with -exec option but it seems something is wrong. The command is find / \( -fstype nfs -o -fstype cachefs -o -fstype ctfs -o \ -...
1
vote
1answer
267 views

replacing current shell with execl()

In the following C program: #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(void){ char *shell = getenv("SHELL"); execl(shell, NULL, NULL); ...
0
votes
2answers
461 views

Dropping filename extensions with find -exec

When using find, how can I drop the original filename extension (i.e. .pdf) from the second pair of -exec braces ({})? For example: find ~/Documents -regex 'LOGIC.*\.pdf' -exec pdf2svg {} {}.svg \; ...
0
votes
1answer
32 views

Passing variables through exe

#!/bin/bash # useradd1.sh - A simple shell script to display the form dialog on screen # set field names i.e. shell variables Name="" OPAC="" Intranet="" mysqlroot="" password="" # open fd # exec 3>...
1
vote
1answer
43 views

Does `exec < somefile` behave the same as `source somefile`

$ cat somefile sleep 100 $ exec < somefile $ sleep 100 Does exec < somefile behave the same as source somefile except that its invoking process terminates upon its completion? Thanks.
6
votes
1answer
509 views

Why does ` exec 2>somefile` hang? [duplicate]

Why does exec >somefile return immediately, while exec 2>somefile doesn't and hang on indefinitely? Thanks.
0
votes
2answers
83 views

will the sleep command in this command ever be executed?

Motivated by How can I change my command to run without superuser privilleges but with the changed limit value?, in a bash shell, if I run exec su $LOGNAME && sleep 100 will the sleep ...
1
vote
1answer
82 views

Does bash calls `execve()` without making further change to how `execve()` treats the signal dispositions?

Bash manual says When a simple command other than a builtin or shell function is to be executed, ... traps caught by the shell are reset to the values inherited from the shell’s parent, and ...
0
votes
1answer
105 views

Change stdout/stderr output device

By default if we run foo(){ echo "myfoo" } it will go to stdout. My question is, for a bash script or function, is there a programmatic way to change the device so that commands don't ...
0
votes
3answers
209 views

Read from file descriptor and write to stdout

I want to prepend something to each line of output in a script, for every command. I was thinking of doing something like this: rm foo mkfifo foo exec 3<>foo cat <&3 | while read line;...
0
votes
0answers
96 views

script appears to run with no progress

This script is to find a list of files stored in a text file, and if the files are found, copy them to a specific location. So far I have had success running the portions up to but not including the ...
0
votes
0answers
84 views

how to know if script execute from local machine or by external engine

we have the following script name checkDataonDataNode_server.bash this script can run local on the linux machine as ./checkDataonDataNode_server.bash or from some win machine that execute this ...
1
vote
2answers
146 views

find + how to verify that all files and folders are with groups and owner hdfs:hadoop

we want to check that all files and folders under /hadoop/hdfs are with permissions - hdfs:hadoop is it possible to do this test with find command ? in case find capture files/folder that not have ...
0
votes
1answer
47 views

Do the strings accessible via global vairable `environ` not reflect any change to the environment?

From https://unix.stackexchange.com/a/436631/674 the file /proc/$$/environ ... does not reflect any changes to the environment, but just reports what the program received when it was execed by the ...
0
votes
0answers
92 views

strace output has dash/hyphen prefix

What does the - prefix signify within ["-bash"] within the line below from the output of an strace command on sshd to trace execve calls? All other execve calls were unprefixed; only bash shows the ...
0
votes
1answer
47 views

Shell script – New script not inheriting values from parent script after `exec`

I wrote a shell script named testmain.sh: username="ravi" echo "The main ProcessId: " echo $$ exec ./process.sh With process.sh being: echo "In subprocess the process ID is:" echo $$ echo $username ...