fork
, exec
, and wait
Q. Can I use the gimp
for "V" viewing purposes instead of xv
?
A. No. Your program should invoke xv
for viewing pictures, as
specified in the project description.
Q. Since i will be creating <login>-picshare.jpg
in /tmp
directory
with some permissions (allow only viewing). the program will not allow
a user (grader) to place"P" a picture in that file, because first
i create this -picshare
file in /tmp
with 644
permission, then
copy specified picture via exec
. And really only owner can place it
this way. Well, i could create file(777
), place specified picture in it
,and only then set the the 644
permission via exec
, is that eficient.
Since i don't know the way grader will be running the program:
as a simple user, root, or through my login, I don't know the right way
to go about this file setup?
A. The TA will run the program as a simple user. However, you don't
really need to worry about that fact because, as the assignment description
says, your program "will name the copy of the picture
<username>-picshare.jpg
, where <username>
is replaced by the user's actual
login name." Since the TA will be the user of the program when he runs it in
order to grade it, it should create picture names using HIS user name, not
yours. So, it won't matter if there is already a picture in the /tmp
directory with your name on it.
Q. Could you tell me how I can access the user's name within UNIX.
A. Next week we'll cover the proper way to do this. For this
assignment, you may use the value in either of two of the user's
environment variables: USER
or USERNAME
.
Q. Here is the code segment that exhibits the behavior I was having a
problem with. Removing the str
functions causes the program to behave
correctly.
#include <unistd.h> #include <string.h> int main(void) { char *temp; char *pic_dir = "/home/user9876/PicDir"; char *new_file = "test.jpg"; strcpy(temp, pic_dir); strcat(temp,"/"); strcat(temp, new_file); printf("executing ls\n"); execlp("ls","ls","-l",(char *) 0); perror("execl failed to run ls"); exit(1); }
A. The problem with this code is that you are not creating any space
into which to store the string being constructed by the
strcpy()
and strcat()
calls. Replace char
*temp;
with char temp [80]
and your program will run
fine. (Actually, instead of an arbitrary number like 80, you should use
the constant PATH_MAX
defined in
<limits.h>
.) This is a common type of mistake to make
when using arrays and pointers in C.