On an IBM Mainframe running z/OS, you run a utility which copies a dataset (file) to another dataset (file). The input is the source of the JCL (Job Control Language) that you have submitted to cause it to run. The output is the Internal Reader (INTRDR). You will also need to ensure that your system does not allow the running of multiple identical jobnames. Good to use a job-class which only has one initiator (place where a JOB can run in batch).
There are no PIDs involved (in z/OS), so fails the challenge set.
You halt the process by draining and/or flushing. If something has gone wrong, by draining and/or flushing, swearing, kicking, attempting a warm-start and finally by a cold-start or hitting the Big Red Button (and shooting the programmer).
I may have exaggerated along the way, but don't try this at work...
Example using SORT. Details on the JOB card are very site-dependant. Site policy may either forbid or prevent the use of INTRDR. A specific class may be required to use the INTRDR. If your site policy forbids its use do not use it unless you want to take your belongings for a walk in a cardboard box.
Although there are good uses for the INTRDR, do not use it for this purpose. You won't even have a chance to get your box.
//jobname JOB rest is to your site standards
//*
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=(,INTRDR) minimum required, site may require more
//SYSIN DD *
OPTION COPY
//SORTIN DD DISP=SHR,DSN=YOUR.LIBRARY.WITHJOB(JOBMEMBR)
Other utilities are available. A quick program would be easy to do as well, just read a file, write a file.
If you want an example of this going wrong, try: http://ibmmainframes.com/viewtopic.php?p=282414#282414
The traditional way to copy a dataset is to use the IBM utility IEBGENER, as ugoren alludes in their comment.
However, these days, many sites will have IEBGENER "aliased" to ICEGENER. ICEGENER will, if it can, use IBM's DFSORT (or its rival SyncSort) to do a copy, because the SORT products are much more hihgly optimised for IO than IEBGENER is.
I'm just cutting out the middle-man by using SORT.
If you work at an IBM Mainframe site, you know the format of the JOB card that you should use. The minimal JOB card is as I have shown, without the comment. The comment will be important, because you may be supposed to be supplying accounting information, for instance. The jobname will likely have a site-specific format.
Some sites ban, or prevent, the use of the INTRDR. Be aware.
Some sites allow multiple jobs with the same name to run at the same time. Be aware.
Although unless you are a System's Programmer you can't set up such a class, you should look for a class which allows only one initiator. With that, the process is fairly safe - but be absolutely sure about that the class is working as described. Test. Not with this job.
If you are a System's Programmer, you know not to do anything outside of your remit. 'nuff said.
With one job with the same name allowed at the same time and a single initiator, this will be a constant stream of job start/finish next job start/finish - until you fill the spool (another bad thing to do) with the output from thousands of jobs (or run out of job numbers). Watch a JES Console for warning messages.
Basically, don't do this. If you do do it, don't do it on a Production machine.
With a little brushing up, I'll consider another Answer for how to do it on another IBM Mainframe operating system, z/VSE... z/VSE uses JCL. z/OS uses JCL. They are different :-)
2Are we allowed to write a supplement program? – Cruncher – 2014-02-21T15:37:40.853
11Isn't this just what
exec
does in linux? – mniip – 2014-02-21T15:41:40.260Supplement programs are allowed, as long as they do not coexist with the main program or with another instance of themselves too, at any point of time. – microbian – 2014-02-21T15:43:21.730
@mniip I don't think the PID changes in this case, so it's arguable that the program never terminates. – Cruncher – 2014-02-21T15:46:38.937
11I'm a little lazy to write it right now, but my submission would be(for windows): "Edit the registry so that my program boots on startup. Run
shutdown -r -t 0 -f
". – Cruncher – 2014-02-21T15:48:52.9933Killing the process won't kill your cycle though. – microbian – 2014-02-21T15:49:49.107
1@microbian It will if you can theoretically end it before the shutdown gets run. If you consider that infeasible you can add as long of a sleep as you want before the shutdown call. – Cruncher – 2014-02-21T15:51:01.363
1@Cruncher, That is doable, though a program without sleep will leave your system unusable :) Since there are no answers yet, I am going to disallow system restarts as valid answers. – microbian – 2014-02-21T15:57:55.540
2@microbian Lol, windows isn't completely dumb. I'm pretty sure if you booted into safe mode you could fix the problem. Or even boot into a linux disk and delete the exe from your harddrive. FYI: You should edit that into your question asap, however I'm not sure what solutions you're looking for. I thought the restart was a nice creative solution for a popularity contest – Cruncher – 2014-02-21T15:59:02.707
2I'd use CreateRemoteThread on a random process to start another instance of the parent program after a short delay, but alas, I'm not on Windows. – tecywiz121 – 2014-02-22T03:07:34.257
Only infinite loop will satisfy your conditions ;) Program that quits and starts itself breaks condition '2 instances at the same time are not allowed', especially 'Not even for a slightest moment of time.' It must start new instance of itself before it quits. Any type of script/scheduler that runs your program breaks condition 'starts itself'. This is very tricky, script is process for itself in this case, it is not a part of program. – None – 2014-02-22T01:58:54.403
19I just realized: if I want to write a virus and don't know how, I could 1) go to StackOverflow, ask how. Get hate from everyone and probably the question will be closed. Or 2) Go to code golf, ask others how they'd do it. Get a handful of creative answers to select from, and the question is so popular it gets on the network-wide "hot" list. Mua ha ha ha ha. – rumtscho – 2014-02-22T15:31:54.717
1
Are building a modern
– ja72 – 2014-02-22T16:39:23.830TSR
here?5@rumtscho You know, that's a good general strategy. Ok guys, for my next challenge, let's see who can write the smallest firmware for the prototype device sitting on my desk that meets all of the requirements in the linked document. To spice it up, this must be done by 8AM Monday morning. Go! – Jason C – 2014-02-22T19:21:13.307