我尝试将计算机名称存储在名为computerName的字符串中。当运行gethostname()时,程序退出并显示退出状态-1。我在想怎么处理这件事。有没有办法防止程序完全退出,有没有办法发现哪里出了问题。gethostname()的文档说明它的错误是EFAULT、EINVAL、ENAMETOOLONG和EPERM。我不知道怎么抓住他们中的任何一个。
问题不在于为什么会发生这个错误,而在于如何处理它。
出现这个错误的原因是因为我在一个有明显限制的在线ide上运行代码,这个错误不会在其他机器上发生。我已经尝试在try and catch(...)中包含代码语句,但它仍然显示exit_status
我不熟悉linux C开发。
我的代码:
....
if((pid=fork())==0){
//child process
//start a process, may be need to change execv to other call
execv (workdir , args);
}else if (pid<0){
...
}else{
...
}
我想要做的是从子进程中立即返回已启动的新进程。
因为在当前的程序中,execv (workdir , args);不会返回。(我需要启动一个长时间运行的进程)。
我想要做的是启动这个长时间运行的进程,并在我
我在操作系统、Linux (Ubuntu和CentOS)和Windows 7中使用相同的源代码编写了一个简单的添加程序,如下所示:
#include <stdio.h>
int main(){
int a,s,d;
printf("type the values u want to add and give tab between them\n");
scanf("%d %d",&a,&s);
d=a+s;
printf("addition is %d",d);
return 0;
system("
在python3.4中,我试图在Linux中使用vlc打开一个"wav“文件。这是我的代码:
import os,time
os.system("cvlc audio/some.wav")
time.sleep(3) #audio was one and half sec
a = 3+3
print (a)
它播放音频,但之后就不播放了。我该怎么做才能让他们这么做?更确切地说,我应该做什么来关闭vlc程序?
随着问题的解决,它也将非常感激知道是否有更容易的方式来播放音频在代码中,特别是在python3.4中?(平台独立代码将更加感激!)
我有如下的java代码:
public class Example{
public static void main(String args[]){
//Done something here
// Start process A
somefunction();
}
public static void somefunction(){
// Done some implementation
System.out.pri