我想以myscript这种方式调用文件:
$ ./myscript -s 45 -p any_string
Run Code Online (Sandbox Code Playgroud)
要么
$ ./myscript -h #should display help
$ ./myscript #should display help
Run Code Online (Sandbox Code Playgroud)
我的要求是:
getopt 这里得到输入参数-s存在,如果没有返回错误-s是45还是90-p存在并且之后有输入字符串./myscript -h或只是./myscript显示帮助我到目前为止尝试了这段代码:
#!/bin/bash
while getopts "h:s:" arg; do
case $arg in
h)
echo "usage"
;;
s)
strength=$OPTARG
echo $strength
;;
esac
done
Run Code Online (Sandbox Code Playgroud)
但是使用该代码我会收到错误.怎么用Bash和getopt?
我在前台启动了我的程序(一个守护程序),然后我用它杀了它kill -9,但我得到了一个僵尸,我无法杀死它kill -9.如何杀死僵尸进程?
如果僵尸是一个死的进程(已经被杀死),我如何从输出中删除它ps aux?
root@OpenWrt:~# anyprogramd &
root@OpenWrt:~# ps aux | grep anyprogram
1163 root 2552 S anyprogramd
1167 root 2552 S anyprogramd
1169 root 2552 S anyprogramd
1170 root 2552 S anyprogramd
10101 root 944 S grep anyprogram
root@OpenWrt:~# pidof anyprogramd
1170 1169 1167 1163
root@OpenWrt:~# kill -9 1170 1169 1167 1163
root@OpenWrt:~# ps aux |grep anyprogram
1163 root 0 Z [cwmpd]
root@OpenWrt:~# kill -9 1163
root@OpenWrt:~# ps aux |grep anyprogram
1163 …Run Code Online (Sandbox Code Playgroud) 在fork子中,如果我们修改一个全局变量,它将不会在主程序中被更改.
有没有办法在子fork中更改全局变量?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int glob_var;
main (int ac, char **av)
{
int pid;
glob_var = 1;
if ((pid = fork()) == 0) {
/* child */
glob_var = 5;
}
else {
/* Error */
perror ("fork");
exit (1);
}
int status;
while (wait(&status) != pid) {
}
printf("%d\n",glob_var); // this will display 1 and not 5.
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试发送补丁git send-email但是我得到以下错误:
git: 'send-email' is not a git command. See 'git --help'.
Run Code Online (Sandbox Code Playgroud)
怎么做git send-email作品?
相关链接:
http://www.kernel.org/pub/software/scm/git/docs/git-send-email.html
我有一个包含以下行的文件:
<parameter name="PortMappingEnabled" access="readWrite" type="xsd:boolean"></parameter>
<parameter name="PortMappingLeaseDuration" access="readWrite" activeNotify="canDeny" type="xsd:unsignedInt"></parameter>
<parameter name="RemoteHost" access="readWrite"></parameter>
<parameter name="ExternalPort" access="readWrite" type="xsd:unsignedInt"></parameter>
<parameter name="ExternalPortEndRange" access="readWrite" type="xsd:unsignedInt"></parameter>
<parameter name="InternalPort" access="readWrite" type="xsd:unsignedInt"></parameter>
<parameter name="PortMappingProtocol" access="readWrite"></parameter>
<parameter name="InternalClient" access="readWrite"></parameter>
<parameter name="PortMappingDescription" access="readWrite"></parameter>
Run Code Online (Sandbox Code Playgroud)
我想在此文件上执行命令以仅提取以下输出中显示的参数名称:
$sedcommand file.txt
PortMappingEnabled
PortMappingLeaseDuration
RemoteHost
ExternalPort
ExternalPortEndRange
InternalPort
PortMappingProtocol
InternalClient
PortMappingDescription
Run Code Online (Sandbox Code Playgroud)
这个命令可能是什么?
我pthread_cond_wait(&cond_t, &mutex);在我的程序中使用,我想知道为什么这个函数需要作为第二个参数mutex变量.
是否pthread_cond_wait()在开始时解锁互斥锁(执行开始pthread_cond_wait())然后在完成时(就在离开之前pthread_cond_wait())锁定?
我正在生成一个git补丁.然后我想将它发送给项目维护者.
我想signed-off-by在git补丁中标记我的姓名和电子邮件地址
怎么做 ?为了让项目维护者获得signed-off-by带有我的姓名和电子邮件地址的字段.
我有一个包含许多行的文件,我想用Linux命令只显示每行的第一个单词.
我怎样才能做到这一点?
awk输出看起来像:
awk '{print $2}'
toto
titi
tata
Run Code Online (Sandbox Code Playgroud)
我想在同一行中以空格作为分隔符而不是新行来显示awk的输出
awk [option] '{print $2}'
toto titi tata
Run Code Online (Sandbox Code Playgroud)
有可能吗?