By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,271 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,271 IT Pros & Developers. It's quick & easy.

Help with scripts .sh files

P: 1
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",dp->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_RDONLY)) != -1) {
printf("File opened\n");
id = (pid_t)atoi(dp->d_name);
printf("%d\n",id);


} 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!
Mar 25 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.