bash

Sending SIGINT to forked exec process which runs script does not kill it

本小妞迷上赌 提交于 2021-02-08 09:19:14
问题 I'm writing shell application with C and encountered a problem that sending SIGINT to process running script won't stop it. Sending the same signal to a normal executable works just fine. Example: Bash script which just imitates long working script (work.sh): #! /bin/bash COUNTER=0 while true do ((COUNTER+=1)) echo "#${COUNTER} Working..." sleep 1 done C code: int main() { pid_t pid = fork(); if (pid == 0) { char* cmds[] = { "./work.sh", NULL }; if (execvp(cmds[0], cmds) == -1) { exit(1); } }

Sending SIGINT to forked exec process which runs script does not kill it

Deadly 提交于 2021-02-08 09:19:01
问题 I'm writing shell application with C and encountered a problem that sending SIGINT to process running script won't stop it. Sending the same signal to a normal executable works just fine. Example: Bash script which just imitates long working script (work.sh): #! /bin/bash COUNTER=0 while true do ((COUNTER+=1)) echo "#${COUNTER} Working..." sleep 1 done C code: int main() { pid_t pid = fork(); if (pid == 0) { char* cmds[] = { "./work.sh", NULL }; if (execvp(cmds[0], cmds) == -1) { exit(1); } }

Send image over http via socat bash webserver

℡╲_俬逩灬. 提交于 2021-02-08 08:59:48
问题 I am trying to write a webserver in bash using socat. I am having trouble serving image requests. I'm opening the socat listening connection like so: socat -T 30 -d -d TCP-L:$LISTENIP,reuseaddr,fork,crlf SYSTEM:"$0 \"docroot=$DOCROOT\"" I'm serving the image with the following, where $1 is the docroot and $2 is the image file name. function serve_png { if [ -e $1$2 ] then SIZE=`stat -c '%s' $1$2` echo -ne "HTTP/1.1 200 OK\nContent-type: image/png\nContent-length: $SIZE\n\n" cat $1$2 else echo

sed: remove whole words containg a character class

蓝咒 提交于 2021-02-08 08:20:18
问题 I'd like to remove any word which contains a non alpha char from a text file. e.g "ok 0bad ba1d bad3 4bad4 5bad5bad5" should become "ok" I've tried using echo "ok 0bad ba1d bad3 4bad4 5bad5bad5" | sed 's/\b[a-zA-Z]*[^a-zA-Z]\+[a-zA-Z]*\b/ /g' 回答1: Using awk : s="ok 0bad ba1d bad3 4bad4 5bad5bad5" awk '{ofs=""; for (i=1; i<=NF; i++) if ($i ~ /^[[:alpha:]]+$/) {printf "%s%s", ofs, $i; ofs=OFS} print ""}' <<< "$s" ok This awk command loops through all words and if word matches the regex /^[[

While loop in bash to read a file skips first 2 characters of THIRD Line

早过忘川 提交于 2021-02-08 08:16:24
问题 #bin/bash INPUT_DIR="$1" INPUT_VIDEO="$2" OUTPUT_PATH="$3" SOURCE="$4" DATE="$5" INPUT="$INPUT_DIR/sorted_result.txt" COUNT=1 initial=00:00:00 while IFS= read -r line; do OUT_DIR=$OUTPUT_PATH/$COUNT mkdir "$OUT_DIR" ffmpeg -nostdin -i $INPUT_VIDEO -vcodec h264 -vf fps=25 -ss $initial -to $line $OUT_DIR/$COUNT.avi ffmpeg -i $OUT_DIR/$COUNT.avi -acodec pcm_s16le -ar 16000 -ac 1 $OUT_DIR/$COUNT.wav python3.6 /home/Video_Audio_Chunks_1.py $OUT_DIR/$COUNT.wav python /home/transcribe.py --decoder

While loop in bash to read a file skips first 2 characters of THIRD Line

荒凉一梦 提交于 2021-02-08 08:14:11
问题 #bin/bash INPUT_DIR="$1" INPUT_VIDEO="$2" OUTPUT_PATH="$3" SOURCE="$4" DATE="$5" INPUT="$INPUT_DIR/sorted_result.txt" COUNT=1 initial=00:00:00 while IFS= read -r line; do OUT_DIR=$OUTPUT_PATH/$COUNT mkdir "$OUT_DIR" ffmpeg -nostdin -i $INPUT_VIDEO -vcodec h264 -vf fps=25 -ss $initial -to $line $OUT_DIR/$COUNT.avi ffmpeg -i $OUT_DIR/$COUNT.avi -acodec pcm_s16le -ar 16000 -ac 1 $OUT_DIR/$COUNT.wav python3.6 /home/Video_Audio_Chunks_1.py $OUT_DIR/$COUNT.wav python /home/transcribe.py --decoder

While loop in bash to read a file skips first 2 characters of THIRD Line

﹥>﹥吖頭↗ 提交于 2021-02-08 08:14:09
问题 #bin/bash INPUT_DIR="$1" INPUT_VIDEO="$2" OUTPUT_PATH="$3" SOURCE="$4" DATE="$5" INPUT="$INPUT_DIR/sorted_result.txt" COUNT=1 initial=00:00:00 while IFS= read -r line; do OUT_DIR=$OUTPUT_PATH/$COUNT mkdir "$OUT_DIR" ffmpeg -nostdin -i $INPUT_VIDEO -vcodec h264 -vf fps=25 -ss $initial -to $line $OUT_DIR/$COUNT.avi ffmpeg -i $OUT_DIR/$COUNT.avi -acodec pcm_s16le -ar 16000 -ac 1 $OUT_DIR/$COUNT.wav python3.6 /home/Video_Audio_Chunks_1.py $OUT_DIR/$COUNT.wav python /home/transcribe.py --decoder

Create bins with awk histogram-like

浪子不回头ぞ 提交于 2021-02-08 07:51:17
问题 Here's my input file : 1.37987 1.21448 0.624999 1.28966 1.77084 1.088 1.41667 I would like to create bins of a size of my choice to get histogram-like output, e.g. something like this for 0.1 bins, starting from 0 : 0 0.1 0 ... 0.5 0.6 0 0.6 0.7 1 ... 1.0 1.1 1 1.1 1.2 0 1.2 1.3 2 1.3 1.4 1 ... My file is too big for R, so I'm looking for an awk solution (also open to anything else that I can understand, as I'm still a Linux beginner). This was sort of already answered in this post : awk

Long lines overlap in Bash PS1 prompt

本秂侑毒 提交于 2021-02-08 07:47:04
问题 I have configured a PS1 bash prompt. My ~/.bashrc file: if [[ $EUID -ne 0 ]]; then PS1='\n\e[0;33m☛ \W\e[0m \n\e[1;35m⤷\e[0m ' fi The problem is that the new line overlaps the previous one. Any idea how to fix this? 回答1: When using non-printing characters in a bash prompt, you have to specify non-printing sequences (e.g. color codes) as non-printing, using \[...\] : PS1='\n\[\e[0;33m\]☛ \W\[\e[0m\] \n\[\e[1;35m\]⤷\[\e[0m\] ' 来源: https://stackoverflow.com/questions/17306348/long-lines-overlap

Long lines overlap in Bash PS1 prompt

南笙酒味 提交于 2021-02-08 07:45:51
问题 I have configured a PS1 bash prompt. My ~/.bashrc file: if [[ $EUID -ne 0 ]]; then PS1='\n\e[0;33m☛ \W\e[0m \n\e[1;35m⤷\e[0m ' fi The problem is that the new line overlaps the previous one. Any idea how to fix this? 回答1: When using non-printing characters in a bash prompt, you have to specify non-printing sequences (e.g. color codes) as non-printing, using \[...\] : PS1='\n\[\e[0;33m\]☛ \W\[\e[0m\] \n\[\e[1;35m\]⤷\[\e[0m\] ' 来源: https://stackoverflow.com/questions/17306348/long-lines-overlap