Is there a way to pause a running process on Linux systems and resume later?Is there any way to attach...
How long has this character been impersonating a Starfleet Officer?
Case protection with emphasis in biblatex
Minimum Viable Product for RTS game?
How to fly a direct entry holding pattern when approaching from an awkward angle?
Co-worker sabotaging/undoing my work (software development)
Charging phone battery with a lower voltage, coming from a bike charger?
Critique vs nitpicking
Other than edits for international editions, did Harry Potter and the Philosopher's Stone receive errata?
How to not let the Identify spell spoil everything?
Crack the bank account's password!
why typing a variable (or expression) prints the value to stdout?
Single-row INSERT...SELECT much slower than separate SELECT
The No-Straight Maze
Eww, those bytes are gross
Count repetitions of an array
Taking an academic pseudonym?
How do I avoid the "chosen hero" feeling?
Can me and my friend spend the summer in Canada (6 weeks) at 16 years old without an adult?
Is it really OK to use "because of"?
What is a good reason for every spaceship to carry gun on board?
How to extract specific values/fields from the text file?
Word for something that's always reliable, but never the best?
How to politely refuse in-office gym instructor for steroids and protein
Is the percentage symbol a constant?
Is there a way to pause a running process on Linux systems and resume later?
Is there any way to attach latrace to an already-running process?How to run linux process and come back to it later?Process history in Unix/Linux systemsIs there a way to suspend an process belongs to shell A and foreground it in shell B?foolproof way to detect if java process is runningHow can I pause or freeze a running process?Why is there no easy way to list all processes in a given process group?Easy way to create a meaningless, cheap, long-running process?Is there a way to change the process group of a running process?Suspend and then resume a process in python scrip - Linux
I have to copy files on a machine. And the data is immensely large. Now servers need to serve normally, and there are usually a particular range of busy hours on those.
So is there a way to run such commands in a way that if server hits busy hours, it pauses process, and when it gets out of that range, it resumes it?
Intended-Result
cp src dst
if time between 9:00-14:00 pause process
After 14:00 resume cp command.
process process-management
add a comment |
I have to copy files on a machine. And the data is immensely large. Now servers need to serve normally, and there are usually a particular range of busy hours on those.
So is there a way to run such commands in a way that if server hits busy hours, it pauses process, and when it gets out of that range, it resumes it?
Intended-Result
cp src dst
if time between 9:00-14:00 pause process
After 14:00 resume cp command.
process process-management
20
rsync can resume partial transfers
– Thorbjørn Ravn Andersen
Feb 21 at 15:37
1
Do you need the actual data to be copied as a backup? If not, could you usecp -alto make a hardlink farm? Or use a filesystem that supports block-level reflinks with copy-on-write, usingcp -a --reflink=auto? BTRFS and ZFS support that for copies within the same physical device.
– Peter Cordes
Feb 21 at 17:05
8
Do any of the files insrcchange between 9:00 and 14:00? If so, simply pausing and resuming thecpprocess may result in corrupted files. It may be better to runrsyncin combination with thetimeoutcommand.
– Mark Plotnick
Feb 21 at 19:51
From and to where are the files being copied? Is this a virtual system? What is the source filesystem? What's the purpose of the copy?
– Braiam
16 hours ago
add a comment |
I have to copy files on a machine. And the data is immensely large. Now servers need to serve normally, and there are usually a particular range of busy hours on those.
So is there a way to run such commands in a way that if server hits busy hours, it pauses process, and when it gets out of that range, it resumes it?
Intended-Result
cp src dst
if time between 9:00-14:00 pause process
After 14:00 resume cp command.
process process-management
I have to copy files on a machine. And the data is immensely large. Now servers need to serve normally, and there are usually a particular range of busy hours on those.
So is there a way to run such commands in a way that if server hits busy hours, it pauses process, and when it gets out of that range, it resumes it?
Intended-Result
cp src dst
if time between 9:00-14:00 pause process
After 14:00 resume cp command.
process process-management
process process-management
edited Feb 21 at 12:37
Rui F Ribeiro
40.5k1479137
40.5k1479137
asked Feb 21 at 12:22
SollosaSollosa
4041717
4041717
20
rsync can resume partial transfers
– Thorbjørn Ravn Andersen
Feb 21 at 15:37
1
Do you need the actual data to be copied as a backup? If not, could you usecp -alto make a hardlink farm? Or use a filesystem that supports block-level reflinks with copy-on-write, usingcp -a --reflink=auto? BTRFS and ZFS support that for copies within the same physical device.
– Peter Cordes
Feb 21 at 17:05
8
Do any of the files insrcchange between 9:00 and 14:00? If so, simply pausing and resuming thecpprocess may result in corrupted files. It may be better to runrsyncin combination with thetimeoutcommand.
– Mark Plotnick
Feb 21 at 19:51
From and to where are the files being copied? Is this a virtual system? What is the source filesystem? What's the purpose of the copy?
– Braiam
16 hours ago
add a comment |
20
rsync can resume partial transfers
– Thorbjørn Ravn Andersen
Feb 21 at 15:37
1
Do you need the actual data to be copied as a backup? If not, could you usecp -alto make a hardlink farm? Or use a filesystem that supports block-level reflinks with copy-on-write, usingcp -a --reflink=auto? BTRFS and ZFS support that for copies within the same physical device.
– Peter Cordes
Feb 21 at 17:05
8
Do any of the files insrcchange between 9:00 and 14:00? If so, simply pausing and resuming thecpprocess may result in corrupted files. It may be better to runrsyncin combination with thetimeoutcommand.
– Mark Plotnick
Feb 21 at 19:51
From and to where are the files being copied? Is this a virtual system? What is the source filesystem? What's the purpose of the copy?
– Braiam
16 hours ago
20
20
rsync can resume partial transfers
– Thorbjørn Ravn Andersen
Feb 21 at 15:37
rsync can resume partial transfers
– Thorbjørn Ravn Andersen
Feb 21 at 15:37
1
1
Do you need the actual data to be copied as a backup? If not, could you use
cp -al to make a hardlink farm? Or use a filesystem that supports block-level reflinks with copy-on-write, using cp -a --reflink=auto? BTRFS and ZFS support that for copies within the same physical device.– Peter Cordes
Feb 21 at 17:05
Do you need the actual data to be copied as a backup? If not, could you use
cp -al to make a hardlink farm? Or use a filesystem that supports block-level reflinks with copy-on-write, using cp -a --reflink=auto? BTRFS and ZFS support that for copies within the same physical device.– Peter Cordes
Feb 21 at 17:05
8
8
Do any of the files in
src change between 9:00 and 14:00? If so, simply pausing and resuming the cp process may result in corrupted files. It may be better to run rsync in combination with the timeout command.– Mark Plotnick
Feb 21 at 19:51
Do any of the files in
src change between 9:00 and 14:00? If so, simply pausing and resuming the cp process may result in corrupted files. It may be better to run rsync in combination with the timeout command.– Mark Plotnick
Feb 21 at 19:51
From and to where are the files being copied? Is this a virtual system? What is the source filesystem? What's the purpose of the copy?
– Braiam
16 hours ago
From and to where are the files being copied? Is this a virtual system? What is the source filesystem? What's the purpose of the copy?
– Braiam
16 hours ago
add a comment |
7 Answers
7
active
oldest
votes
You can pause execution of a process by sending it a SIGSTOP signal and then later resume it by sending it a SIGCONT.
Assuming your workload is a single process (doesn't fork helpers running in background), you can use something like this:
# start copy in background, store pid
cp src dst &
echo "$!" >/var/run/bigcopy.pid
Then when busy time starts, send it a SIGSTOP:
# pause execution of bigcopy
kill -STOP "$(cat /var/run/bigcopy.pid)"
Later on, when the server is idle again, resume it.
# resume execution of bigcopy
kill -CONT "$(cat /var/run/bigcopy.pid)"
You will need to schedule this for specific times when you want it executed, you can use tools such as cron or systemd timers (or a variety of other similar tools) to get this scheduled. Instead of scheduling based on a time interval, you might choose to monitor the server (perhaps looking at load average, cpu usage or activity from server logs) to make a decision of when to pause/resume the copy.
You also need to manage the PID file (if you use one), make sure your copy is actually still running before pausing it, probably you'll want to clean up by removing the pidfile once the copy is finished, etc.
In other words, you need more around this to make a reliable, but the base idea of using these SIGSTOP and SIGCONT signals to pause/resume execution of a process seems to be what you're looking for.
6
+1 See also utcc.utoronto.ca/~cks/space/blog/unix/SIGSTOPUsesAndCautions
– bishop
Feb 21 at 16:50
1
Maybe add a reminder that you should be very careful that '/var/run/bigcopy.pid' still refers to the same process as you think it does. randomly stopping other processes on the system may not be desirable. I know of no safe way to ensure that the pid refers to the program you think it does though...
– Evan Benn
Feb 22 at 2:27
@EvanBenn Yeah that's what I meant in a way with "make sure your copy is actually still running before pausing it" though your point is surely more explicit than that! Yeah checking PIDs is inherently race-y so it's sometimes not really possible to do it 100% reliably...
– filbranden
Feb 22 at 3:02
@cat Not really, a process can't block SIGSTOP. See the link from the first comment: "SIGSTOP is a non-blockable signal like SIGKILL" (or just google it, you'll see that's the case.)
– filbranden
Feb 22 at 3:42
add a comment |
Instead of suspending the process, you could also give it lower priority:
renice 19 "$pid"
will give it the lowest priority (highest niceness), so that process will yield the CPU to other processes that need it most of the time.
On Linux, the same can be done with I/O with ionice:
ionice -c idle -p "$pid"
Will put the process in the "idle" class, so that it will only get disk time when no other program has asked for disk I/O for a defined grace period.
21
This is a typical case of an XY problem. The question was how to pause a process, but this does not answer the question. While indeed lowering the priority is the better approach to the actual problem, it does not answer the question. I would edit the question to also include how to pause a process and why pausing might be a problem (e.g. file could be edited while paused).
– David Stockinger
Feb 21 at 16:47
22
@DavidStockinger, technically, this answer tells how to tell the OS to pause the process when it (the OS, CPU, I/O scheduler) is busy (even if it's for fractions of seconds at a time). How to suspend the process manually has already been covered in other answers. This solution doesn't address the problem of files being modified whilst they are being copied.
– Stéphane Chazelas
Feb 21 at 16:59
5
Changing the I/O priority isn't always the best solution. If you're copying from spinning disks, you may still incur a seek before each high-priority request which you wouldn't incur if you completely paused the low-priority operation.
– Mark
Feb 21 at 22:37
2
Lower priority does not even solve the problem. Even if the box is completely idle for a few seconds or minutes, that does not mean that a huge copy process which will evict everything from the filesystem cache is going to be unobtrusive. As soon as there's a load again, it's going to be very slow paging everything back in.
– R..
2 days ago
2
@DavidStockinger the preferred way of dealing with XY problems is to give the right solution, even if that's not what the question is asking for. When you know the approach described in the question is wrong, then a good answer doesn't give that wrong approach but instead proposes a better one.
– terdon♦
yesterday
|
show 1 more comment
Yes, you Need to
acquire the process id of the process-to-paus (PS), then do
$> kill -SIGSTOP <pid>
The process will then Show up with Status "T" (PS). To continue do a
$> kill -CONT <pid>
Good Luck!
add a comment |
Use rsync, forget about cp, for this scenario.
there are params to limit bandwith, or can be killed/stoped and started later, in a way it will continue, where it left
google rsync example/s
New contributor
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
If you are going to do it by interrupting the running process, I suggest playing with the Screen program. I haven't used Linux in a while, but IIRC just pausing the command and resuming it later leaves you pretty vulnerable, if you accidentally get logged off you won't be able to resume your session.
With screen I believe you can interrupt the session then detach it and log out. Later you can go back in and reattach to that session. You'd have to play with it a bit but it made sessions much more robust.
You can also log out and go home then log in remotely, reattach to the system y you started in the office and resume it for the evening, then pick it up again the next day at work.
I'm already using tmux for tha. But I'm writing a script that would be self-aware or preferably environment-aware, so it stops if server gets high traf, and continue when it's normal.
– Sollosa
22 hours ago
add a comment |
If your shell supports it (almost all do), you can press ^Z (Ctrl+Z) to easily send a SIGTSTP signal to the foreground task, then continue it with fg (on foreground) or bg (on background).
If you do this on multiple tasks and want to return to them later, you can use jobs command, then return with fg/bg %#, where # is the number given in brackets on jobs.
Keep in mind that SIGTSTP is a bit different than SIGSTOP (which is used on all other answers), most importantly due to the fact that it can be ignored (but I didn't see a program ignore it other than sl). More details can be found on this answer on StackOverflow.
New contributor
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Surprised that no answer mentioned this yet.
– Ave
1 hour ago
add a comment |
This can be easily achieved by emitting SIGSTOP signal and SIGCONT to re-initiate the process
New contributor
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
11
This doesn't add anything beyond what 3 other answers already provide.
– JoL
Feb 21 at 18:16
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502065%2fis-there-a-way-to-pause-a-running-process-on-linux-systems-and-resume-later%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can pause execution of a process by sending it a SIGSTOP signal and then later resume it by sending it a SIGCONT.
Assuming your workload is a single process (doesn't fork helpers running in background), you can use something like this:
# start copy in background, store pid
cp src dst &
echo "$!" >/var/run/bigcopy.pid
Then when busy time starts, send it a SIGSTOP:
# pause execution of bigcopy
kill -STOP "$(cat /var/run/bigcopy.pid)"
Later on, when the server is idle again, resume it.
# resume execution of bigcopy
kill -CONT "$(cat /var/run/bigcopy.pid)"
You will need to schedule this for specific times when you want it executed, you can use tools such as cron or systemd timers (or a variety of other similar tools) to get this scheduled. Instead of scheduling based on a time interval, you might choose to monitor the server (perhaps looking at load average, cpu usage or activity from server logs) to make a decision of when to pause/resume the copy.
You also need to manage the PID file (if you use one), make sure your copy is actually still running before pausing it, probably you'll want to clean up by removing the pidfile once the copy is finished, etc.
In other words, you need more around this to make a reliable, but the base idea of using these SIGSTOP and SIGCONT signals to pause/resume execution of a process seems to be what you're looking for.
6
+1 See also utcc.utoronto.ca/~cks/space/blog/unix/SIGSTOPUsesAndCautions
– bishop
Feb 21 at 16:50
1
Maybe add a reminder that you should be very careful that '/var/run/bigcopy.pid' still refers to the same process as you think it does. randomly stopping other processes on the system may not be desirable. I know of no safe way to ensure that the pid refers to the program you think it does though...
– Evan Benn
Feb 22 at 2:27
@EvanBenn Yeah that's what I meant in a way with "make sure your copy is actually still running before pausing it" though your point is surely more explicit than that! Yeah checking PIDs is inherently race-y so it's sometimes not really possible to do it 100% reliably...
– filbranden
Feb 22 at 3:02
@cat Not really, a process can't block SIGSTOP. See the link from the first comment: "SIGSTOP is a non-blockable signal like SIGKILL" (or just google it, you'll see that's the case.)
– filbranden
Feb 22 at 3:42
add a comment |
You can pause execution of a process by sending it a SIGSTOP signal and then later resume it by sending it a SIGCONT.
Assuming your workload is a single process (doesn't fork helpers running in background), you can use something like this:
# start copy in background, store pid
cp src dst &
echo "$!" >/var/run/bigcopy.pid
Then when busy time starts, send it a SIGSTOP:
# pause execution of bigcopy
kill -STOP "$(cat /var/run/bigcopy.pid)"
Later on, when the server is idle again, resume it.
# resume execution of bigcopy
kill -CONT "$(cat /var/run/bigcopy.pid)"
You will need to schedule this for specific times when you want it executed, you can use tools such as cron or systemd timers (or a variety of other similar tools) to get this scheduled. Instead of scheduling based on a time interval, you might choose to monitor the server (perhaps looking at load average, cpu usage or activity from server logs) to make a decision of when to pause/resume the copy.
You also need to manage the PID file (if you use one), make sure your copy is actually still running before pausing it, probably you'll want to clean up by removing the pidfile once the copy is finished, etc.
In other words, you need more around this to make a reliable, but the base idea of using these SIGSTOP and SIGCONT signals to pause/resume execution of a process seems to be what you're looking for.
6
+1 See also utcc.utoronto.ca/~cks/space/blog/unix/SIGSTOPUsesAndCautions
– bishop
Feb 21 at 16:50
1
Maybe add a reminder that you should be very careful that '/var/run/bigcopy.pid' still refers to the same process as you think it does. randomly stopping other processes on the system may not be desirable. I know of no safe way to ensure that the pid refers to the program you think it does though...
– Evan Benn
Feb 22 at 2:27
@EvanBenn Yeah that's what I meant in a way with "make sure your copy is actually still running before pausing it" though your point is surely more explicit than that! Yeah checking PIDs is inherently race-y so it's sometimes not really possible to do it 100% reliably...
– filbranden
Feb 22 at 3:02
@cat Not really, a process can't block SIGSTOP. See the link from the first comment: "SIGSTOP is a non-blockable signal like SIGKILL" (or just google it, you'll see that's the case.)
– filbranden
Feb 22 at 3:42
add a comment |
You can pause execution of a process by sending it a SIGSTOP signal and then later resume it by sending it a SIGCONT.
Assuming your workload is a single process (doesn't fork helpers running in background), you can use something like this:
# start copy in background, store pid
cp src dst &
echo "$!" >/var/run/bigcopy.pid
Then when busy time starts, send it a SIGSTOP:
# pause execution of bigcopy
kill -STOP "$(cat /var/run/bigcopy.pid)"
Later on, when the server is idle again, resume it.
# resume execution of bigcopy
kill -CONT "$(cat /var/run/bigcopy.pid)"
You will need to schedule this for specific times when you want it executed, you can use tools such as cron or systemd timers (or a variety of other similar tools) to get this scheduled. Instead of scheduling based on a time interval, you might choose to monitor the server (perhaps looking at load average, cpu usage or activity from server logs) to make a decision of when to pause/resume the copy.
You also need to manage the PID file (if you use one), make sure your copy is actually still running before pausing it, probably you'll want to clean up by removing the pidfile once the copy is finished, etc.
In other words, you need more around this to make a reliable, but the base idea of using these SIGSTOP and SIGCONT signals to pause/resume execution of a process seems to be what you're looking for.
You can pause execution of a process by sending it a SIGSTOP signal and then later resume it by sending it a SIGCONT.
Assuming your workload is a single process (doesn't fork helpers running in background), you can use something like this:
# start copy in background, store pid
cp src dst &
echo "$!" >/var/run/bigcopy.pid
Then when busy time starts, send it a SIGSTOP:
# pause execution of bigcopy
kill -STOP "$(cat /var/run/bigcopy.pid)"
Later on, when the server is idle again, resume it.
# resume execution of bigcopy
kill -CONT "$(cat /var/run/bigcopy.pid)"
You will need to schedule this for specific times when you want it executed, you can use tools such as cron or systemd timers (or a variety of other similar tools) to get this scheduled. Instead of scheduling based on a time interval, you might choose to monitor the server (perhaps looking at load average, cpu usage or activity from server logs) to make a decision of when to pause/resume the copy.
You also need to manage the PID file (if you use one), make sure your copy is actually still running before pausing it, probably you'll want to clean up by removing the pidfile once the copy is finished, etc.
In other words, you need more around this to make a reliable, but the base idea of using these SIGSTOP and SIGCONT signals to pause/resume execution of a process seems to be what you're looking for.
answered Feb 21 at 12:48
filbrandenfilbranden
9,22621342
9,22621342
6
+1 See also utcc.utoronto.ca/~cks/space/blog/unix/SIGSTOPUsesAndCautions
– bishop
Feb 21 at 16:50
1
Maybe add a reminder that you should be very careful that '/var/run/bigcopy.pid' still refers to the same process as you think it does. randomly stopping other processes on the system may not be desirable. I know of no safe way to ensure that the pid refers to the program you think it does though...
– Evan Benn
Feb 22 at 2:27
@EvanBenn Yeah that's what I meant in a way with "make sure your copy is actually still running before pausing it" though your point is surely more explicit than that! Yeah checking PIDs is inherently race-y so it's sometimes not really possible to do it 100% reliably...
– filbranden
Feb 22 at 3:02
@cat Not really, a process can't block SIGSTOP. See the link from the first comment: "SIGSTOP is a non-blockable signal like SIGKILL" (or just google it, you'll see that's the case.)
– filbranden
Feb 22 at 3:42
add a comment |
6
+1 See also utcc.utoronto.ca/~cks/space/blog/unix/SIGSTOPUsesAndCautions
– bishop
Feb 21 at 16:50
1
Maybe add a reminder that you should be very careful that '/var/run/bigcopy.pid' still refers to the same process as you think it does. randomly stopping other processes on the system may not be desirable. I know of no safe way to ensure that the pid refers to the program you think it does though...
– Evan Benn
Feb 22 at 2:27
@EvanBenn Yeah that's what I meant in a way with "make sure your copy is actually still running before pausing it" though your point is surely more explicit than that! Yeah checking PIDs is inherently race-y so it's sometimes not really possible to do it 100% reliably...
– filbranden
Feb 22 at 3:02
@cat Not really, a process can't block SIGSTOP. See the link from the first comment: "SIGSTOP is a non-blockable signal like SIGKILL" (or just google it, you'll see that's the case.)
– filbranden
Feb 22 at 3:42
6
6
+1 See also utcc.utoronto.ca/~cks/space/blog/unix/SIGSTOPUsesAndCautions
– bishop
Feb 21 at 16:50
+1 See also utcc.utoronto.ca/~cks/space/blog/unix/SIGSTOPUsesAndCautions
– bishop
Feb 21 at 16:50
1
1
Maybe add a reminder that you should be very careful that '/var/run/bigcopy.pid' still refers to the same process as you think it does. randomly stopping other processes on the system may not be desirable. I know of no safe way to ensure that the pid refers to the program you think it does though...
– Evan Benn
Feb 22 at 2:27
Maybe add a reminder that you should be very careful that '/var/run/bigcopy.pid' still refers to the same process as you think it does. randomly stopping other processes on the system may not be desirable. I know of no safe way to ensure that the pid refers to the program you think it does though...
– Evan Benn
Feb 22 at 2:27
@EvanBenn Yeah that's what I meant in a way with "make sure your copy is actually still running before pausing it" though your point is surely more explicit than that! Yeah checking PIDs is inherently race-y so it's sometimes not really possible to do it 100% reliably...
– filbranden
Feb 22 at 3:02
@EvanBenn Yeah that's what I meant in a way with "make sure your copy is actually still running before pausing it" though your point is surely more explicit than that! Yeah checking PIDs is inherently race-y so it's sometimes not really possible to do it 100% reliably...
– filbranden
Feb 22 at 3:02
@cat Not really, a process can't block SIGSTOP. See the link from the first comment: "SIGSTOP is a non-blockable signal like SIGKILL" (or just google it, you'll see that's the case.)
– filbranden
Feb 22 at 3:42
@cat Not really, a process can't block SIGSTOP. See the link from the first comment: "SIGSTOP is a non-blockable signal like SIGKILL" (or just google it, you'll see that's the case.)
– filbranden
Feb 22 at 3:42
add a comment |
Instead of suspending the process, you could also give it lower priority:
renice 19 "$pid"
will give it the lowest priority (highest niceness), so that process will yield the CPU to other processes that need it most of the time.
On Linux, the same can be done with I/O with ionice:
ionice -c idle -p "$pid"
Will put the process in the "idle" class, so that it will only get disk time when no other program has asked for disk I/O for a defined grace period.
21
This is a typical case of an XY problem. The question was how to pause a process, but this does not answer the question. While indeed lowering the priority is the better approach to the actual problem, it does not answer the question. I would edit the question to also include how to pause a process and why pausing might be a problem (e.g. file could be edited while paused).
– David Stockinger
Feb 21 at 16:47
22
@DavidStockinger, technically, this answer tells how to tell the OS to pause the process when it (the OS, CPU, I/O scheduler) is busy (even if it's for fractions of seconds at a time). How to suspend the process manually has already been covered in other answers. This solution doesn't address the problem of files being modified whilst they are being copied.
– Stéphane Chazelas
Feb 21 at 16:59
5
Changing the I/O priority isn't always the best solution. If you're copying from spinning disks, you may still incur a seek before each high-priority request which you wouldn't incur if you completely paused the low-priority operation.
– Mark
Feb 21 at 22:37
2
Lower priority does not even solve the problem. Even if the box is completely idle for a few seconds or minutes, that does not mean that a huge copy process which will evict everything from the filesystem cache is going to be unobtrusive. As soon as there's a load again, it's going to be very slow paging everything back in.
– R..
2 days ago
2
@DavidStockinger the preferred way of dealing with XY problems is to give the right solution, even if that's not what the question is asking for. When you know the approach described in the question is wrong, then a good answer doesn't give that wrong approach but instead proposes a better one.
– terdon♦
yesterday
|
show 1 more comment
Instead of suspending the process, you could also give it lower priority:
renice 19 "$pid"
will give it the lowest priority (highest niceness), so that process will yield the CPU to other processes that need it most of the time.
On Linux, the same can be done with I/O with ionice:
ionice -c idle -p "$pid"
Will put the process in the "idle" class, so that it will only get disk time when no other program has asked for disk I/O for a defined grace period.
21
This is a typical case of an XY problem. The question was how to pause a process, but this does not answer the question. While indeed lowering the priority is the better approach to the actual problem, it does not answer the question. I would edit the question to also include how to pause a process and why pausing might be a problem (e.g. file could be edited while paused).
– David Stockinger
Feb 21 at 16:47
22
@DavidStockinger, technically, this answer tells how to tell the OS to pause the process when it (the OS, CPU, I/O scheduler) is busy (even if it's for fractions of seconds at a time). How to suspend the process manually has already been covered in other answers. This solution doesn't address the problem of files being modified whilst they are being copied.
– Stéphane Chazelas
Feb 21 at 16:59
5
Changing the I/O priority isn't always the best solution. If you're copying from spinning disks, you may still incur a seek before each high-priority request which you wouldn't incur if you completely paused the low-priority operation.
– Mark
Feb 21 at 22:37
2
Lower priority does not even solve the problem. Even if the box is completely idle for a few seconds or minutes, that does not mean that a huge copy process which will evict everything from the filesystem cache is going to be unobtrusive. As soon as there's a load again, it's going to be very slow paging everything back in.
– R..
2 days ago
2
@DavidStockinger the preferred way of dealing with XY problems is to give the right solution, even if that's not what the question is asking for. When you know the approach described in the question is wrong, then a good answer doesn't give that wrong approach but instead proposes a better one.
– terdon♦
yesterday
|
show 1 more comment
Instead of suspending the process, you could also give it lower priority:
renice 19 "$pid"
will give it the lowest priority (highest niceness), so that process will yield the CPU to other processes that need it most of the time.
On Linux, the same can be done with I/O with ionice:
ionice -c idle -p "$pid"
Will put the process in the "idle" class, so that it will only get disk time when no other program has asked for disk I/O for a defined grace period.
Instead of suspending the process, you could also give it lower priority:
renice 19 "$pid"
will give it the lowest priority (highest niceness), so that process will yield the CPU to other processes that need it most of the time.
On Linux, the same can be done with I/O with ionice:
ionice -c idle -p "$pid"
Will put the process in the "idle" class, so that it will only get disk time when no other program has asked for disk I/O for a defined grace period.
answered Feb 21 at 14:23
Stéphane ChazelasStéphane Chazelas
307k57581936
307k57581936
21
This is a typical case of an XY problem. The question was how to pause a process, but this does not answer the question. While indeed lowering the priority is the better approach to the actual problem, it does not answer the question. I would edit the question to also include how to pause a process and why pausing might be a problem (e.g. file could be edited while paused).
– David Stockinger
Feb 21 at 16:47
22
@DavidStockinger, technically, this answer tells how to tell the OS to pause the process when it (the OS, CPU, I/O scheduler) is busy (even if it's for fractions of seconds at a time). How to suspend the process manually has already been covered in other answers. This solution doesn't address the problem of files being modified whilst they are being copied.
– Stéphane Chazelas
Feb 21 at 16:59
5
Changing the I/O priority isn't always the best solution. If you're copying from spinning disks, you may still incur a seek before each high-priority request which you wouldn't incur if you completely paused the low-priority operation.
– Mark
Feb 21 at 22:37
2
Lower priority does not even solve the problem. Even if the box is completely idle for a few seconds or minutes, that does not mean that a huge copy process which will evict everything from the filesystem cache is going to be unobtrusive. As soon as there's a load again, it's going to be very slow paging everything back in.
– R..
2 days ago
2
@DavidStockinger the preferred way of dealing with XY problems is to give the right solution, even if that's not what the question is asking for. When you know the approach described in the question is wrong, then a good answer doesn't give that wrong approach but instead proposes a better one.
– terdon♦
yesterday
|
show 1 more comment
21
This is a typical case of an XY problem. The question was how to pause a process, but this does not answer the question. While indeed lowering the priority is the better approach to the actual problem, it does not answer the question. I would edit the question to also include how to pause a process and why pausing might be a problem (e.g. file could be edited while paused).
– David Stockinger
Feb 21 at 16:47
22
@DavidStockinger, technically, this answer tells how to tell the OS to pause the process when it (the OS, CPU, I/O scheduler) is busy (even if it's for fractions of seconds at a time). How to suspend the process manually has already been covered in other answers. This solution doesn't address the problem of files being modified whilst they are being copied.
– Stéphane Chazelas
Feb 21 at 16:59
5
Changing the I/O priority isn't always the best solution. If you're copying from spinning disks, you may still incur a seek before each high-priority request which you wouldn't incur if you completely paused the low-priority operation.
– Mark
Feb 21 at 22:37
2
Lower priority does not even solve the problem. Even if the box is completely idle for a few seconds or minutes, that does not mean that a huge copy process which will evict everything from the filesystem cache is going to be unobtrusive. As soon as there's a load again, it's going to be very slow paging everything back in.
– R..
2 days ago
2
@DavidStockinger the preferred way of dealing with XY problems is to give the right solution, even if that's not what the question is asking for. When you know the approach described in the question is wrong, then a good answer doesn't give that wrong approach but instead proposes a better one.
– terdon♦
yesterday
21
21
This is a typical case of an XY problem. The question was how to pause a process, but this does not answer the question. While indeed lowering the priority is the better approach to the actual problem, it does not answer the question. I would edit the question to also include how to pause a process and why pausing might be a problem (e.g. file could be edited while paused).
– David Stockinger
Feb 21 at 16:47
This is a typical case of an XY problem. The question was how to pause a process, but this does not answer the question. While indeed lowering the priority is the better approach to the actual problem, it does not answer the question. I would edit the question to also include how to pause a process and why pausing might be a problem (e.g. file could be edited while paused).
– David Stockinger
Feb 21 at 16:47
22
22
@DavidStockinger, technically, this answer tells how to tell the OS to pause the process when it (the OS, CPU, I/O scheduler) is busy (even if it's for fractions of seconds at a time). How to suspend the process manually has already been covered in other answers. This solution doesn't address the problem of files being modified whilst they are being copied.
– Stéphane Chazelas
Feb 21 at 16:59
@DavidStockinger, technically, this answer tells how to tell the OS to pause the process when it (the OS, CPU, I/O scheduler) is busy (even if it's for fractions of seconds at a time). How to suspend the process manually has already been covered in other answers. This solution doesn't address the problem of files being modified whilst they are being copied.
– Stéphane Chazelas
Feb 21 at 16:59
5
5
Changing the I/O priority isn't always the best solution. If you're copying from spinning disks, you may still incur a seek before each high-priority request which you wouldn't incur if you completely paused the low-priority operation.
– Mark
Feb 21 at 22:37
Changing the I/O priority isn't always the best solution. If you're copying from spinning disks, you may still incur a seek before each high-priority request which you wouldn't incur if you completely paused the low-priority operation.
– Mark
Feb 21 at 22:37
2
2
Lower priority does not even solve the problem. Even if the box is completely idle for a few seconds or minutes, that does not mean that a huge copy process which will evict everything from the filesystem cache is going to be unobtrusive. As soon as there's a load again, it's going to be very slow paging everything back in.
– R..
2 days ago
Lower priority does not even solve the problem. Even if the box is completely idle for a few seconds or minutes, that does not mean that a huge copy process which will evict everything from the filesystem cache is going to be unobtrusive. As soon as there's a load again, it's going to be very slow paging everything back in.
– R..
2 days ago
2
2
@DavidStockinger the preferred way of dealing with XY problems is to give the right solution, even if that's not what the question is asking for. When you know the approach described in the question is wrong, then a good answer doesn't give that wrong approach but instead proposes a better one.
– terdon♦
yesterday
@DavidStockinger the preferred way of dealing with XY problems is to give the right solution, even if that's not what the question is asking for. When you know the approach described in the question is wrong, then a good answer doesn't give that wrong approach but instead proposes a better one.
– terdon♦
yesterday
|
show 1 more comment
Yes, you Need to
acquire the process id of the process-to-paus (PS), then do
$> kill -SIGSTOP <pid>
The process will then Show up with Status "T" (PS). To continue do a
$> kill -CONT <pid>
Good Luck!
add a comment |
Yes, you Need to
acquire the process id of the process-to-paus (PS), then do
$> kill -SIGSTOP <pid>
The process will then Show up with Status "T" (PS). To continue do a
$> kill -CONT <pid>
Good Luck!
add a comment |
Yes, you Need to
acquire the process id of the process-to-paus (PS), then do
$> kill -SIGSTOP <pid>
The process will then Show up with Status "T" (PS). To continue do a
$> kill -CONT <pid>
Good Luck!
Yes, you Need to
acquire the process id of the process-to-paus (PS), then do
$> kill -SIGSTOP <pid>
The process will then Show up with Status "T" (PS). To continue do a
$> kill -CONT <pid>
Good Luck!
answered Feb 21 at 12:46
gerhard d.gerhard d.
1,216310
1,216310
add a comment |
add a comment |
Use rsync, forget about cp, for this scenario.
there are params to limit bandwith, or can be killed/stoped and started later, in a way it will continue, where it left
google rsync example/s
New contributor
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Use rsync, forget about cp, for this scenario.
there are params to limit bandwith, or can be killed/stoped and started later, in a way it will continue, where it left
google rsync example/s
New contributor
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Use rsync, forget about cp, for this scenario.
there are params to limit bandwith, or can be killed/stoped and started later, in a way it will continue, where it left
google rsync example/s
New contributor
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Use rsync, forget about cp, for this scenario.
there are params to limit bandwith, or can be killed/stoped and started later, in a way it will continue, where it left
google rsync example/s
New contributor
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 2 days ago
Anton TománekAnton Tománek
611
611
New contributor
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Anton Tománek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
If you are going to do it by interrupting the running process, I suggest playing with the Screen program. I haven't used Linux in a while, but IIRC just pausing the command and resuming it later leaves you pretty vulnerable, if you accidentally get logged off you won't be able to resume your session.
With screen I believe you can interrupt the session then detach it and log out. Later you can go back in and reattach to that session. You'd have to play with it a bit but it made sessions much more robust.
You can also log out and go home then log in remotely, reattach to the system y you started in the office and resume it for the evening, then pick it up again the next day at work.
I'm already using tmux for tha. But I'm writing a script that would be self-aware or preferably environment-aware, so it stops if server gets high traf, and continue when it's normal.
– Sollosa
22 hours ago
add a comment |
If you are going to do it by interrupting the running process, I suggest playing with the Screen program. I haven't used Linux in a while, but IIRC just pausing the command and resuming it later leaves you pretty vulnerable, if you accidentally get logged off you won't be able to resume your session.
With screen I believe you can interrupt the session then detach it and log out. Later you can go back in and reattach to that session. You'd have to play with it a bit but it made sessions much more robust.
You can also log out and go home then log in remotely, reattach to the system y you started in the office and resume it for the evening, then pick it up again the next day at work.
I'm already using tmux for tha. But I'm writing a script that would be self-aware or preferably environment-aware, so it stops if server gets high traf, and continue when it's normal.
– Sollosa
22 hours ago
add a comment |
If you are going to do it by interrupting the running process, I suggest playing with the Screen program. I haven't used Linux in a while, but IIRC just pausing the command and resuming it later leaves you pretty vulnerable, if you accidentally get logged off you won't be able to resume your session.
With screen I believe you can interrupt the session then detach it and log out. Later you can go back in and reattach to that session. You'd have to play with it a bit but it made sessions much more robust.
You can also log out and go home then log in remotely, reattach to the system y you started in the office and resume it for the evening, then pick it up again the next day at work.
If you are going to do it by interrupting the running process, I suggest playing with the Screen program. I haven't used Linux in a while, but IIRC just pausing the command and resuming it later leaves you pretty vulnerable, if you accidentally get logged off you won't be able to resume your session.
With screen I believe you can interrupt the session then detach it and log out. Later you can go back in and reattach to that session. You'd have to play with it a bit but it made sessions much more robust.
You can also log out and go home then log in remotely, reattach to the system y you started in the office and resume it for the evening, then pick it up again the next day at work.
answered Feb 21 at 23:17
Bill KBill K
224210
224210
I'm already using tmux for tha. But I'm writing a script that would be self-aware or preferably environment-aware, so it stops if server gets high traf, and continue when it's normal.
– Sollosa
22 hours ago
add a comment |
I'm already using tmux for tha. But I'm writing a script that would be self-aware or preferably environment-aware, so it stops if server gets high traf, and continue when it's normal.
– Sollosa
22 hours ago
I'm already using tmux for tha. But I'm writing a script that would be self-aware or preferably environment-aware, so it stops if server gets high traf, and continue when it's normal.
– Sollosa
22 hours ago
I'm already using tmux for tha. But I'm writing a script that would be self-aware or preferably environment-aware, so it stops if server gets high traf, and continue when it's normal.
– Sollosa
22 hours ago
add a comment |
If your shell supports it (almost all do), you can press ^Z (Ctrl+Z) to easily send a SIGTSTP signal to the foreground task, then continue it with fg (on foreground) or bg (on background).
If you do this on multiple tasks and want to return to them later, you can use jobs command, then return with fg/bg %#, where # is the number given in brackets on jobs.
Keep in mind that SIGTSTP is a bit different than SIGSTOP (which is used on all other answers), most importantly due to the fact that it can be ignored (but I didn't see a program ignore it other than sl). More details can be found on this answer on StackOverflow.
New contributor
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Surprised that no answer mentioned this yet.
– Ave
1 hour ago
add a comment |
If your shell supports it (almost all do), you can press ^Z (Ctrl+Z) to easily send a SIGTSTP signal to the foreground task, then continue it with fg (on foreground) or bg (on background).
If you do this on multiple tasks and want to return to them later, you can use jobs command, then return with fg/bg %#, where # is the number given in brackets on jobs.
Keep in mind that SIGTSTP is a bit different than SIGSTOP (which is used on all other answers), most importantly due to the fact that it can be ignored (but I didn't see a program ignore it other than sl). More details can be found on this answer on StackOverflow.
New contributor
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Surprised that no answer mentioned this yet.
– Ave
1 hour ago
add a comment |
If your shell supports it (almost all do), you can press ^Z (Ctrl+Z) to easily send a SIGTSTP signal to the foreground task, then continue it with fg (on foreground) or bg (on background).
If you do this on multiple tasks and want to return to them later, you can use jobs command, then return with fg/bg %#, where # is the number given in brackets on jobs.
Keep in mind that SIGTSTP is a bit different than SIGSTOP (which is used on all other answers), most importantly due to the fact that it can be ignored (but I didn't see a program ignore it other than sl). More details can be found on this answer on StackOverflow.
New contributor
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If your shell supports it (almost all do), you can press ^Z (Ctrl+Z) to easily send a SIGTSTP signal to the foreground task, then continue it with fg (on foreground) or bg (on background).
If you do this on multiple tasks and want to return to them later, you can use jobs command, then return with fg/bg %#, where # is the number given in brackets on jobs.
Keep in mind that SIGTSTP is a bit different than SIGSTOP (which is used on all other answers), most importantly due to the fact that it can be ignored (but I didn't see a program ignore it other than sl). More details can be found on this answer on StackOverflow.
New contributor
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 1 hour ago
AveAve
1036
1036
New contributor
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Ave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Surprised that no answer mentioned this yet.
– Ave
1 hour ago
add a comment |
Surprised that no answer mentioned this yet.
– Ave
1 hour ago
Surprised that no answer mentioned this yet.
– Ave
1 hour ago
Surprised that no answer mentioned this yet.
– Ave
1 hour ago
add a comment |
This can be easily achieved by emitting SIGSTOP signal and SIGCONT to re-initiate the process
New contributor
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
11
This doesn't add anything beyond what 3 other answers already provide.
– JoL
Feb 21 at 18:16
add a comment |
This can be easily achieved by emitting SIGSTOP signal and SIGCONT to re-initiate the process
New contributor
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
11
This doesn't add anything beyond what 3 other answers already provide.
– JoL
Feb 21 at 18:16
add a comment |
This can be easily achieved by emitting SIGSTOP signal and SIGCONT to re-initiate the process
New contributor
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This can be easily achieved by emitting SIGSTOP signal and SIGCONT to re-initiate the process
New contributor
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Feb 21 at 17:06
anonyanony
12
12
New contributor
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
anony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
11
This doesn't add anything beyond what 3 other answers already provide.
– JoL
Feb 21 at 18:16
add a comment |
11
This doesn't add anything beyond what 3 other answers already provide.
– JoL
Feb 21 at 18:16
11
11
This doesn't add anything beyond what 3 other answers already provide.
– JoL
Feb 21 at 18:16
This doesn't add anything beyond what 3 other answers already provide.
– JoL
Feb 21 at 18:16
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502065%2fis-there-a-way-to-pause-a-running-process-on-linux-systems-and-resume-later%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
20
rsync can resume partial transfers
– Thorbjørn Ravn Andersen
Feb 21 at 15:37
1
Do you need the actual data to be copied as a backup? If not, could you use
cp -alto make a hardlink farm? Or use a filesystem that supports block-level reflinks with copy-on-write, usingcp -a --reflink=auto? BTRFS and ZFS support that for copies within the same physical device.– Peter Cordes
Feb 21 at 17:05
8
Do any of the files in
srcchange between 9:00 and 14:00? If so, simply pausing and resuming thecpprocess may result in corrupted files. It may be better to runrsyncin combination with thetimeoutcommand.– Mark Plotnick
Feb 21 at 19:51
From and to where are the files being copied? Is this a virtual system? What is the source filesystem? What's the purpose of the copy?
– Braiam
16 hours ago