471,122 Members | 1,148 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

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",dp->d_name); //It outputs

//Afterwards,the program cannot open any file and the output is
//File couldn't be opened
//File couldn't be opened
//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);

} 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
0 5460

Post your reply

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

Similar topics

4 posts views Thread by Jm | last post: by
1 post views Thread by treelife | last post: by
37 posts views Thread by John Salerno | last post: by
17 posts views Thread by Saps | last post: by
reply views Thread by wb5plj | last post: by
reply views Thread by alpnz | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.