unix

behavior of parent and child for a signal handler

☆樱花仙子☆ 提交于 2021-02-17 21:39:30
问题 A process has a 'fork' call after a signal handler has been registered [for SIGINT]. what happens when SIGINT is sent through command line ? whether parent gets exited or child or both ? parent and child both are running infinite while loops. 回答1: If you do fork (without further exec* ) after a signal handler has been registered, the same signal handler will be used in parent and child processes. That is, if you do something other than exit in your SIGINT handler, neither parent nor child

Python scripts in /usr/bin

社会主义新天地 提交于 2021-02-17 15:16:41
问题 I'm writing a pretty basic application in python (it's only one file at the moment). My question is how do I get it so the python script is able to be run in /usr/bin without the .py extension? For example, instead of running python htswap.py args from the directory where it currently is, I want to be able to cd to any directory and do htswap args Thanks in advance! 回答1: Simply strip off the .py extension by renaming the file. Then, you have to put the following line at the top of your file:

How to understand the output of time command?

谁说胖子不能爱 提交于 2021-02-17 09:17:51
问题 I am trying to figure out the performance of my code, but I do not understand the output of the time command, Can anybody please explain what does time command output means. The following is what I get: time ./filereader real 0m0.193s user 0m0.012s sys 0m0.056s What is real , user , sys ? 回答1: From: http://zch051383471952.blogspot.com/2010/01/different-of-real-user-sys-time.html Real refers to actual elapsed time; User and Sys refer to CPU time used only by the process. Real is wall clock

How to understand the output of time command?

对着背影说爱祢 提交于 2021-02-17 09:15:03
问题 I am trying to figure out the performance of my code, but I do not understand the output of the time command, Can anybody please explain what does time command output means. The following is what I get: time ./filereader real 0m0.193s user 0m0.012s sys 0m0.056s What is real , user , sys ? 回答1: From: http://zch051383471952.blogspot.com/2010/01/different-of-real-user-sys-time.html Real refers to actual elapsed time; User and Sys refer to CPU time used only by the process. Real is wall clock

Which of sprintf/snprintf is more secure?

做~自己de王妃 提交于 2021-02-17 08:20:26
问题 I wish to know which of these two options is the more secure one to use: #define MAXLEN 255 char buff[MAXLEN + 1] sprintf(buff, "%.*s", MAXLEN, name) snprintf(buff, MAXLEN, "%s", name) My understanding is that both are same. Please suggest. 回答1: The two expressions you gave are not equivalent: sprintf takes no argument specifying the maximum number of bytes to write; it simply takes a destination buffer, a format string, and a bunch of arguments. Therefore, it may write more bytes than your

Which of sprintf/snprintf is more secure?

天大地大妈咪最大 提交于 2021-02-17 08:20:11
问题 I wish to know which of these two options is the more secure one to use: #define MAXLEN 255 char buff[MAXLEN + 1] sprintf(buff, "%.*s", MAXLEN, name) snprintf(buff, MAXLEN, "%s", name) My understanding is that both are same. Please suggest. 回答1: The two expressions you gave are not equivalent: sprintf takes no argument specifying the maximum number of bytes to write; it simply takes a destination buffer, a format string, and a bunch of arguments. Therefore, it may write more bytes than your

How do -s and -p alter the read command?

风流意气都作罢 提交于 2021-02-17 05:36:06
问题 I'm trying to interpret this block of code. Searched google to see what these commands mean and no luck. I put my interpretation of what each line/block means to me. If I am wrong, please correct me. I am new to unix commands. Code: #!/bin/bash # input 1st command line argument for the version. export VERSION=$1 # if user didn't input a version, print the echo message and exit (not sure what -n means but I am assuming) if [[ ! -n "$VERSION" ]]; then echo "Missing Version" exit 1 fi # creating

Manage serial port from two processes simultaneosly

半世苍凉 提交于 2021-02-17 05:28:25
问题 I have the following scenario: Rasperry pi connected to a device via Serial port 3g Dongle connected to the raspberry (with the ability to make/recieve calls) One process reading the data from the serial port and redirecting it to a server (using 3g) Another process waiting for a incoming call, and when someone calls the program takes the data from the serial port and redirect it via the 3g dongle using AT commands ( like fax-call). When someone calls, the call is made using AT commands and

cd to a folder name starting with tilde (~) in bash script

此生再无相见时 提交于 2021-02-16 21:15:29
问题 I'm trying to create a very simple bash script that does the following: Inputs the user to enter a project folder Sets the value entered in a variable cd to the folder entered remove the readme.md file From what I've read around I've come up with this: #!/bin/bash echo "Enter the project folder path:" read -e DESTINATION_FOLDER cd "$DESTINATION_FOLDER" rm -rf "$DESTINATION_FOLDER/readme.md" The folder's path I entered was ~/Dropbox/myproject And the error I get is the one below. However that

command to Substract two timestamps in unix

▼魔方 西西 提交于 2021-02-16 20:15:07
问题 I am writing a script and which requires to calculate the difference between the two timestamps . I have done some search but didn't get a clue so far. For Example say: time1 = 20160314 10:16:27 time2 = 20160313 15:17:28 From the above I need to get result like below: difference is: " 1 day 5 hours 1 minute 1 second " Please help me in resolving this. 回答1: datediff() { t1=$(date -d "$1" +%s) t2=$(date -d "$2" +%s) diff=$(( $t1 - $t2 )) echo "Duration: $(( $diff / 86400 )) days $(($diff / 3600