小编Req*_*iem的帖子

检查文件是否存在(由命令行参数给出)

我必须使用unix环境做一个C程序.我已经购买了"在Unix环境中推进编程"一书,到目前为止已经帮了很多忙.但是,我的一些问题没有得到答复,我正在寻求一些帮助.

我正在尝试编写一个程序,可以验证是否存在复制程序时输入的第一个和第二个参数.如果第一个参数不存在,则必须出现错误消息并退出.如果第二个参数确实存在,则必须显示覆盖提示.我不确定如何验证文件是否已经存在或基本上没有.

我见过一些人说你可以做(​​!-e)或类似的东西来验证文件是否存在.

如果有人能帮助我,我真的很感激.

c unix

5
推荐指数
1
解决办法
1万
查看次数

在java中迭代

我必须创建一个自定义迭代器,它通过一个数组无休止地迭代.考虑到我之前从未使用过java中的迭代器,我不知道如何做到这一点.如果有人能帮我解释并向我解释,我会非常感激.

public class Numbers{   
private int[] array;

public Numbers(int[] array){ 
    this.array = array
}
    public static void main(String[] args) {

        Numbers n = new Numbers();
        Iterator num = n.sequence();
        for(int i = 0; i < 10; i++){
            if (num.hasNext()){
                System.out.print(num.next() + " ");
                System.out.println();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java iterator

4
推荐指数
1
解决办法
446
查看次数

在C中将进程放在后台

我目前潜入创建一个backgrounding工作C&.我需要实现非阻塞waitpid才能使其正常工作.我知道.此外,如果&在命令行末尾输入,我已经抓住了这个条件.我只是不确定如何准确地将进程作为后台作业发送,并将其实现为执行,而另一个提示是提示下一个命令.
任何事情都会有所帮助,谢谢.

    struct bgprocess{
        int pid;
        struct bgprocess * next;
        struct bgprocess * prev;    
    };

    struct bgprocess * bgprocess1;
    bgprocess1 = malloc(sizeof(struct bgprocess));
    bgprocess1->prev = NULL;
    bgprocess1->next = NULL;
    bgprocess1->pid = NULL;

    struct bgprocess * current;
    current = bgprocess1;

    do{
        int bgreturn = 0;
        while (current != NULL){
            if (waitpid(current->pid, &bgreturn, WNOHANG)){
                printf("Child exited");
                current->prev->next = current->next;
                current->next->prev = current->prev;
                current->prev = NULL;
                current->next = NULL;
                free(current);                  
            }
        current = current->next;    
        } …
Run Code Online (Sandbox Code Playgroud)

c unix background-process

4
推荐指数
1
解决办法
7119
查看次数

x86指令含义

我现在在gdb上运行一些代码,我不知道这两个指令实际上是做什么的.如果有人能帮助我,我真的很感激.

add  -0x2c(%ebp, %ebx, 4), %eax
cmp  %eax, -0x28(%ebp, %ebx, 4)
Run Code Online (Sandbox Code Playgroud)

x86 assembly att addressing-mode

2
推荐指数
1
解决办法
906
查看次数

根据列中的重复项从数据中删除整行

所以这是我的问题.我有一个巨大的数据文本文件,我需要通过显然使用java程序快速将所有这些数据输入到mySQL数据库中.我唯一的问题是,数据是由某个ID标识的.这些ID中的一些具有重复并且包含与彼此相同的所有信息.我想删除所有这些用于分类目的和清晰度.

最好的方法是什么?如果有人可以提供帮助,我会很感激!

谢谢.

java mysql database duplicates

1
推荐指数
1
解决办法
675
查看次数

用C编程shell

我目前正在用C语言编写一个shell,我遇到了一些问题.例如,当我尝试将我的命令与"退出"进行比较时,它只是对它进行写操作,并且根据gdb它们的行为不相同.我以段错误结束.如果有人能帮我弄清楚什么是错的,我会非常感激.这是我的第一个shell btw!

#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <limits.h>
#include <unistd.h>
#include <stdlib.h>
#include <pwd.h>
#include <dirent.h>e
#include <sys/types.h>
#include <sys/wait.h>    
#include <signal.h>
#include "sh.h"

int sh( int argc, char **argv, char **envp ){

    char *prompt = calloc(PROMPTMAX, sizeof(char));
    char *commandline = calloc(MAX_CANON, sizeof(char));
    char *command, *arg, *commandpath, *p, *pwd, *owd;
    char **args = calloc(MAXARGS, sizeof(char*));
    int uid, i, status, argsct, go = 1;
    struct passwd *password_entry;
    char *homedir;
    struct pathelement *pathlist;

    uid = getuid();
    password_entry = getpwuid(uid);
    homedir …
Run Code Online (Sandbox Code Playgroud)

c unix shell

0
推荐指数
1
解决办法
1644
查看次数