Help with scripts .sh files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • G_P_H_M
    New Member
    • Mar 2006
    • 1

    Help with scripts .sh files

    Good morning!

    I have a difficulty in openning an .sh file,Here is my code
    (hello directory consists of one file jobs.sh)

    struct dirent *dp;
    DIR *dirp;
    int fd;
    pid_t id;

    if((dirp = opendir(/home/user/hello))) { //open the directory

    while((dp = readdir(dirp))) {
    printf("%s\n",d p->d_name); //It outputs
    //.
    //..
    //jobs.sh

    //Afterwards,the program cannot open any file and the output is
    //.
    //File couldn't be opened
    //..
    //File couldn't be opened
    //jobs.sh
    //File couldn't be opened


    if( (fd = open("dp->d_name",O_RDON LY)) != -1) {
    printf("File opened\n");
    id = (pid_t)atoi(dp->d_name);
    printf("%d\n",i d);


    } else {

    printf("File couldn't be opened\n");

    }

    }


    I dunno what i have done wrong,I'm sure about the path of the directory cause inside the directory i have typed the pwd command,also the file has 700 permission and the perror message is that it doesn't exist.

    Could you please help me?

    i would like to ask you sthg else,as well!
    Every script when it is executed has a number which is the process ID of the script.How do i find this ID?I mean which function shall i use in order to find it?

    Thanks,in advance!
Working...