Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
This question does not appear to be about programming within the scope defined in the help center.
Improve this question
Is it possible to have two linux users with slight delays on their clocks?
The reason I ask is I have two scripts executed by the cron every minute (one on each user). One script copies a file from the another machine the other loads the data in the file into mysql.
We have been finding the loading of the data misses the first minute 90% of the time. I think this is because it is called exactly the same time as the call to copy the file from the other machine is executed.
If I could delay the user clock whose cron executes the loading script by 5 seconds i think this would solve the problem.
Perhaps there is another way of achieving this? Something easier I am missing. I would like the first script to be called every round minute and the second to be called 5seconds after every round minute.
Add a sleep 5 or sleep 10 to the start of the cron entry.
Probably the best answer to this is to set up xntp so the clocks are in sync. Then, as glglgl suggests, put a sleep at the top of the script you want delayed.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have program that I need to run and then see how much resources it uses in unix by using top command. But I don't know how to do it because if i run it from command line I cant use top command till program is finished and vice versa. How can I do it. I tried doing:
sleep 10s
top
./myProgram
But its not working
Open two terminals; run your program in one terminal and top in another.
If you're in a graphical environment, you can just start the terminal a second time.
If you're on the text-only console, you can switch between terminals using Ctrl-Alt-F1..F6 (possibly more) or Alt-Left/Right.
If you connect via SSH, just open multiple terminal sessions in your SSH client.
(Also, I'd hint to use htop instead of top, but you may need to install it first.)
In case your program is too short-lived to show up on top/htop, you might need to run it using Valgrind.
Open two terminals one for running top, and run your program in the other.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I want to use the command "at" to schedule a job to run at one second (or minute/hour) later. If using "-t" option, then it involves with the hassle of getting the current time etc. Is there any easy way out?
But don't suggest me to use "sleep", because the current process will exit.
Thanks for the tip.
The at program can take now+ a time unit (e.g. now+1minute) as a timespec. You won't get finer time resolution than one minute with at.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I understand that /proc/* contains directories that are actually PIDs.
I have a custom process that is killed and spawned every few minutes.
What are the chances of a PID (for example, 1009) getting reused by the custom process? (After wrapping around pid_max)
Is it likely enough to happen that my code should deal with it?
High enough that you should expect it to happen and be prepared to deal with it. The actual probability will of course depend on how often other processes are being created on your system. There is certainly no guarantee that it won't happen, though, so you must assume that it will.
"What are the odds" is a statistics question, and the answer depends on how many other processes there are, and how often they fork() and how often they exit(), so the exact answer is difficult to calculate. Anywhere between "almost impossible to happen" and "nearly guaranteed to happen every minute."
If the question is "could this happen in my lifetime and should I handle that in my code" then the answer is yes.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Sorry if this question seems to be foolish. I want to know how can i put my CPU to work that it's usage increase in arbitrary time. for example i want to turn it over 90 % usage.
if Linux command exists or a simple program to do that it will be a pleasure.
Start running BOINC and use your spare capacity to process data for science. You can control how much of your CPU (and GPU) you assign to background processing and you never know - you may be the one to provide the trigger for a cure for cancer or muscular dystrophy.
Keeps you machine occupied doing something useful while you're taking your time punching keys...
Try the following program, compiled in C++
int main() {
for (;;)
;
}
It will sit in a tight loop and chew up available clock cycles.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have a text file containing a specific date and time.
I want to be able to run a script at the time specified in that file.
How would you achieve that?
Create another script that runs in background (sort of a deamon) and checks every second if the current time is matching the time in the file?
Is there another way?
The machine is a linux server , Debian wheezy.
Thanks in advance
Look at the following:
echo "ls -l" | at 07:00
This code line executes "ls -l" at a specific time. This is an example of executing something (a command in my example) at a specific time. "at" is the command you were really looking for. You can read the specifications here:
http://manpages.ubuntu.com/manpages/precise/en/man1/at.1posix.html
http://manpages.ubuntu.com/manpages/xenial/man1/at.1posix.html
The at command exists specifically for this purpose (unlike cron which is intended for scheduling recurring tasks).
at $(cat file) </path/to/script
Cron is good for something that will run periodically, like every Saturday at 4am. There's also anacron, which works around power shutdowns, sleeps, and whatnot. As well as at.
But for a one-off solution, that doesn't require root or anything, you can just use date to compute the seconds-since-epoch of the target time as well as the present time, then use expr to find the difference, and sleep that many seconds.
Usually in Linux you use crontab for this kind of scduled tasks. But you have to specify the time when you "setup the timer" - so if you want it to be configurable in the file itself, you will have to create some mechanism to do that.
But in general, you would use for example:
30 1 * * 5 /path/to/script/script.sh
Would execute the script every Friday at 1:30 (AM)
Here:
30 is minutes
1 is hour
next 2 *'s are day of month and month (in that order) and 5 is weekday