user3247903
user3247903

Reputation: 69

Process executing (exec) program

My program should read a user id and password. How to make it work through processes.

Upvotes: 1

Views: 47

Answers (1)

grubs
grubs

Reputation: 181

1) Read up on the execl() function. This function does not return. When the validate program ends the child will exit. Hence your write() calls never happen.

2) You appear to be calling execl() on the source code. You would need to compile the source code into an executable program in order to run it this way. Check if execl() is failing like this:

execl("/bin/bash", "bash", "-c", "echo hello", NULL); // Only returns if execl fails
perror("execl failed");
exit(1); // Make sure child exits if execl fails

3) After calling fork you should check for (pid==0) for the child. You are incorrectly testing for (pid), which will be true for the parent not for the child.

4) The write() calls should be made by the parent, not by the child. After the child exec's it will become the validate program and will never return to your code.

That's a start. Good luck!

Upvotes: 2

Related Questions