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.

0
votes
2answers
26 views

Chaining find exec and a while loop

I'm trying to stack a find command so that the results it returns only contains files with "warning:" or "error:" text within them. I also require those results in a specific format so I'm using exec ...
0
votes
2answers
40 views

Print all subdirectories in the current directory that do not contain a .git

I'm trying to write a bash line that will look at all the subdirectories in my current folder and tell me if any do NOT contain a ".git". Pseudo: for subdir in currentdir if .git does not exist ...
-1
votes
0answers
30 views

Why does the fork-exec sequence clone the shell?

As I understand it, the fork-exec sequence sequence goes something like this: a shell finds and interprets a command. The shell then duplicates itself exactly, with a new process ID (the 'fork') and ...
2
votes
0answers
32 views

How does linux decide the load address and entry point when execve an ELF?

When linux execve() an ELF, it will mmap that ELF into the process's memory space and start to run code from the entry point. But how does the kernel decide the load address and entry point of the ELF?...
0
votes
1answer
13 views

CronJob command to delete multiple subdirectories by name in a given directory

I have two IP cameras which are sending image snapshots to an FTP server every 10 seconds, from 08:00 to 20:59. The directory structure looks like this: `-- public_html `-- securitycams |-...
1
vote
2answers
54 views

Why does `find -type d -exec rmdir {} \;` command produce “No such file or directory message”

For testing purposes, I created the following directories. user@linux:~$ mkdir dir0{1..3} user@linux:~$ ls -l total 12K drwxr-xr-x 2 user user 4.0K Mei 31 10:45 dir01 drwxr-xr-x 2 user user 4.0K ...
2
votes
1answer
59 views

How to execute something in current shell [duplicate]

I want to create a bash script or something similar that I can execute in the current shell: echo '#!/bin/bash export foo="bar" ' > zoom.sh but if I want to run this script in the current ...
0
votes
1answer
36 views

Redirecting to both screen and file

I'd like to redirect all of the output of the commands I ran to a file, in addition to having them printed on the screen. I want this to happen automatically, I don't want to pipe into tee everytime ...
-2
votes
1answer
48 views

Does execvp() account for logical operators?

In my class assignment I'm supposed to make my own command shell. In the shell, I am supposed to have it take various command line arguments including logical operators such as && and ||. I ...
2
votes
2answers
215 views

Does running exec do anything?

Does running exec in an interactive shell do anything? I mean simply exec, with no parameters whatsoever. What about in a script? If it does do something, what does it do?
1
vote
2answers
301 views

exec command in bash loop for webscrapping

Here is a simple script which is curling https://unix.stackexchange.com/ and storing the result into an array, which is working fine. #!/usr/local/bin/bash [ -f pgtoscrap ] && { rm pgtoscrap; ...
3
votes
1answer
55 views

Exit status of command in pipeline

I have come across this code but cannot understand exec >&p edit 1 to my understanding : #! /usr/bin/ksh exec 4>&1 ## standard output is first saved as file descriptor 4 ...
1
vote
0answers
69 views

awk print tab delimited columns with find execdir

I am trying to print out columns that are separated by tabs. First, I use find command to identify a list of files to process. Second, I parse the file path to generate the filename to be used for ...
2
votes
1answer
56 views

redirect awk exec results to another folder [duplicate]

Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end. I plan ...
0
votes
0answers
118 views

PHP shell_exec to run debian system service

I'm trying to control a system service with PHP's shell_exec function : shell_exec('sudo /usr/sbin/service icecast2 stop'); But the only way I can get it to work is by allowing ALL users root access ...
7
votes
2answers
446 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
385 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 ...
0
votes
1answer
85 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
138 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
47 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 ...
3
votes
1answer
299 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
39 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
109 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 ...
-2
votes
1answer
77 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 ...
4
votes
1answer
96 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
143 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
3k 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
124 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
38 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
167 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
186 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
190 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
138 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
2k 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
145 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
51 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
49 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
236 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'...
2
votes
1answer
90 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
62 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
418 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
323 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
203 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
305 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
39 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
276 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
94 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
374 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
vote
1answer
344 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
932 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 \; ...