Category: Linux & Mac

[Bash] Kill all processes matching the given pattern

Linux & MacSystem Command

Recently I am in need of shutting down multiple java processes all at once in the development environment, so I finally came up with a bash script to obtain all java process ids and kill them.

ps -aux | grep "java" | grep -v "grep" | awk '{print $2}' | while read -r pid ; do
    echo "Shutting down PID: $pid"
    kill $pid
done

Details:

  1. ps -aux: List all processes。
  2. grep "java": Filter all processes containing java in the commands.
  3. grep -v "grep": Surpress the current shell scipt process.
  4. awk '{print $2}': Preserve process id in column 2 and delete all other columns.
  5. Loop through all pids and kill them.

Using FFmpeg concatenate multiple videos

ApplicationLinux & Mac

Some cameras split a sigle video into multiple files during recoding due to the limitation of the maximum file size in the file system(E.g. maximum single file size for FAT32 is 4GB). In this post, we will take advantage of FFmpeg to merge back our video fragments into a continuous single video.

 

To begin with, we put all our video fragments into the same folder and create a new file called clips.txt. Next, we add the filenames of the video fragments into clips.txt in the order we want to concatenate and seperate them by new lines.

An example of clips.txt.

file 'first.mp4'
file 'second.mp4'
...

Last, running the following command will generate the concatenated video named output.mp4 for us:)

ffmpeg -f concat -i clips.txt -c copy output.mp4