I need to write a C program (not a C++ program) that allows some tasks to be preformed automatically from a menu-driven interface. Automate the following tasks:
1. Rename a file
2. Delete a file or a directory
3. Output Process Information
4. Execute “mode 644 ls -l”
5. Exit
I need to know what steps should I follow to achieve the result. is it possible to ask the user to enter all the names and commands in 1 line or I should ask him one by one.
thank you
It's possible to do it either way. Line-by-line is probably easier.
Your using scanf incorrectly every time you use it. You can't store a string in a char, since a string is a char array, and you shouldn't be using scanf to read raw data. Read lines then feed them into sscanf, or your code may get stuck in infinite loops whenever the user types something wrong.
I'd do this:
Also, you cannot store an entire string inside a single character. You'll need to feed sscanf an array for the filenames. Something like this:
System calls you'll need are unlink to remove files, open to read or create files, read to read from files, write to write to files, and close to close file descriptors once you're done.
That is just like writing a script, not calling system calls
find is based on the nftw() call and uses stat semantics - it returns among other things a struct stat.
To answer your question--
You should consider system(). It calls execl for you and then calls waitpid.
The reason to call syscalls directly in C instead of using execl() is to eliminate process creation which has a lot of overhead that you have in a shell script. system() and execl() are doing nothing you cannot do in a shell script in this case.
It really looks to me like you are expected to use system calls like chmod(), unlink(), and
nftw() or readdir(). Embedding shell commands does not appear (to me) to be what is expected.
When you delete a directory, you have to delete all the files in the directory first. Then unlink the directory itself. Exactly what
does
Hi friends,
I hope everyone is fine and doing well. I queried in my previous thread about the low-level qualities of C/C++ languages.I really thank you people for explaining, it was really helpful. One more ambiquity that I have in my mind is regarding the unix system calls like open, creat,... (1 Reply)
Hi friends,
I have three questions.
1) What are system calls?
2) Is it necessary that system calls be in c language (in unix operating system)?
3) Importance of c language when programming in unix environment???
Looking forward to your wonderful replies!
... (2 Replies)
Hello,
how would i be able to call ps in C programming?
thanks,
---------- Post updated at 01:39 AM ---------- Previous update was at 01:31 AM ----------
here's the complete system call, ps -o pid -p %d, getpit() (2 Replies)
Hi,
I'm new to UNIX system calls. Can someone share your knowledge as to how exactly system calls should be executed?
Can they be typed like commands such as mkdir on the terminal itself? Also, are there any websites which will show me an example of the output to expect when a system call like... (1 Reply)
open, creat, read, write, lseek and close
Are they all primitive?
:confused:
*Another Question: is there a different between a system call, and an i/o system call? (2 Replies)