Short answers,
1. Same as you would in a C application.
2. Ditto - you can't.
Long answers.
1. Why? Call system("ntpdate ntp_server_address") - this will set the system time to the global clock. Guaranteed accurate. If you want to set it to your own value, use system("date date+time_value").
2. The problem here is that you will need to input the password for the root account, and that cannot be done if the process is being run in the background. So, for security reasons, you really can't do that. In a shell, running the command "su -" will request the password for the root account, and if the calling process is backgrounded (no stdin), then it will fail.
rubberman
Posting Virtuoso
1,559 posts since Mar 2010
Reputation Points: 277
Solved Threads: 178
Well, you can enable the setuid bit on the date command (chmod +s /bin/date), then use the system("date time_val") to set the date+time in your C/C++ program.
rubberman
Posting Virtuoso
1,559 posts since Mar 2010
Reputation Points: 277
Solved Threads: 178