I want to script an alarm to be triggered when any of crucial to me processes enters a D state (uninterruptible sleep).
In order to test it, I want to have a dummy script to enter D state and trigger the alarm.
How that can be achieved? Maybe with some one-liner?
Related
I know how to run one cron job after another from this: https://askubuntu.com/questions/923260/cron-run-a-script-after-the-other
But, if I have jobs A, B, and C, how do I make job C wait for BOTH A and B to be finished? Either A or B could finish first, and C cannot start running until both A and B have finished.
I would just put the entire thing into a script and use standard process management, something like:
#!/bin/env bash
jobA & # start A in the background.
jobB # start B in the foreground, A and B running.
wait # B now finished, wait for A if necessary.
jobC # A and B now finished, do C.
I'm working on a program that would simulate scheduling from creation to completion of processes. I need assistance to know can a process move back from ready queue to the job queue (in any case - may be an exception).
I'm not sure what you mean by "queue job". A process is either :
running (in that case no need to do anything)
sleeping, that means that the process is waiting for an input or an output. You can't force it to “wake up”. It'll wake up when the input or output operation it wants to make is possible.
stopped, that means that the process is currently suspended. There four different kind for it.
SIGTSTP, (most of the time triggered by CTRL + Z. Can be unstopped with fg command
SIGSTOP, meaning it has been roughly stopped. Can't do many things about that one.
SIGTTIN and SIGTTOU, but I don't have the knowledge for those two.
So you can dive in fg command that might helps you.
NB : sorry for bad english.
I have two services A and B which I want to start on boot. But A should start first and then only B should start.
I enabled the services using systemctl enable service_name.
Now the services are starting but not in order i.e B is starting before A. Is there any way I can configure their start order?
You can add the following command at the end of the startup script of A, and disable B to be started on bootup: systemctl start B
They're starting out of order because Linux uses "makefile style concurrent boot" during startup -- and the A process is taking longer to start than the B process. The simplest way to delay process B is with a sleep command -- a few seconds is likely enough -- though this will delay the completion of startup by a fixed amount (and, if process A takes a variable time to start, as with opening a wifi connection etc., this may not always work unless you set the time higher than it usually needs to be).
More reliable, and possibly less delay in startup, would be to use something like lsproc | grep proc_a | wc -l to check for existence of process A (or a child of A) as a condition for starting process B -- put this in a short loop with a 1 or 2 second sleep (so it doesn't hog all your CPU while it waits) and it'll effectively keep B back until A is running, without unnecessary delay.
I implemented a simple c shell to take in commands like sleep 3 &. I also implemented it to "listen" for sigchild signals once the job complete.
But how do I get the job id and command to be printed out like the ubuntu shell once it is completed?
I would advise against catching SIGCHLD signals.
A neater way to do that is to call waitpid with the WNOHANG option. If it returns 0, you know that the job with that particular pid is still running, otherwise that process has terminated and you fetch its exit code from the status parameter, and print the message accordingly.
Moreover, bash doesn't print the job completion status at the time the job completes, but rather at the time when the next command is issued, so this is a perfect fit for waitpid.
A small disadvantage of that approach is that the job process will stay as a zombie in the period between its termination and the time you call waitpid, but that probably shouldn't matter for a shell.
You need to remember the child pid (from the fork) and the command executed in your shell (in some sort of table or map structure). Then, when you get a SIGCHILD, you find the child pid and that gives you the corresponding command.
I coded a monitoring program in RPG that checks if the fax/400 is operational.
And now I want this program to check every 15 minutes.
Instead of placing a job every 15 minutes in the job scheduler (which would be ugly to manage), I made the program wait between checks using DLYJOB.
Now how can I make this program "place itself" in memory so it keeps running?
(I thought of using SBMJOB, but I can't figure in which job queue I could place it.)
A good job queue to use for an endlessly running job would be QSYSNOMAX. That allows unlimited numbers of jobs to be running.
You could submit the job to that queue in your QSTRTUP program and it will simply remain running all the time.
Here what I have done in the past. There are two approaches to this.
Submit a new job every time the program runs with DLYJOB before it runs.
Create a loop and only end given a certain condition.
What I did with a Monitor MSGW program was the following:
PGM
DCL VAR(&TIME) TYPE(*CHAR) LEN(6)
DCL VAR(&STOPTIME) TYPE(*CHAR) LEN(6) +
VALUE('200000')
/* Setup my program (run only once) */
START:
/* Perform my actions */
RTVSYSVAL SYSVAL(QTIME) RTNVAR(&TIME)
IF COND(&TIME *GE &STOPTIME) THEN(GOTO CMDLBL(END))
DLYJOB DLY(180)
GOTO CMDLBL(START)
END:
ENDPGM
This will run continuously until 8:00 pm. Then I add this to the job scheduler to submit every morning.
As far as which jobq. I am using QINTER, but it could really be run anywhere. Make sure you choose a subsystem with enough available running jobs as this will take one.
The negative of running in QINTER if the program starts to hit 100% CPU, that will use up all of your interactive CPU and effectively locks up your system.
i know of 3 ways to that.
1) using Data queue, there is parm to tell it to wait endlessly and at time-interval.
2) using OVRDBF cmd, there is parm there to tell that it should not end or EOF, making your pgm to keep on waiting.
3) easiest to implement, sbmjob to call a pgm that loops forever eg with DOW 1=1, you can insert a code to check for certain time interval before it iterates. You can have your logic inside the loop that checks for fax, process it and then back to waiting.