UNIX Free Pascal


         


13.51. .

uses dos;

var

cmd:string;

begin

while true do

begin

write('> ');

readln(cmd);

if cmd='exit' then

break

else

begin

cmd:='-c '+cmd;

writeln(' ',cmd);

exec('/bin/sh',cmd);

end;

end;

end.

 

13.52. , .

uses linux;

const

_SC_ARG_MAX=1;

_SC_CHILD_MAX=2;

_SC_CLK_TCK=3;

_SC_NGROUPS_MAX=4;

_SC_OPEN_MAX=5;

_SC_STREAM_MAX=6;

_SC_TZNAME_MAX=7;

_SC_JOB_CONTROL=8;

_SC_SAVED_IDS=9;

_SC_REALTIME_SIGNALS=10;

_SC_PRIORITY_SCHEDULING=11;

_SC_TIMERS=12;

_SC_ASYNCHRONOUS_IO=13;

_SC_PRIORITIZED_IO=14;

_SC_SYNCHRONIZED_IO=15;

_SC_FSYNC=16;

_SC_MAPPED_FILES=17;

_SC_MEMLOCK=18;

_SC_MEMLOCK_RANGE=19;

_SC_MEMORY_PROTECTION=20;

_SC_MESSAGE_PASSING=21;

_SC_SEMAPHORES=22;

_SC_SHARED_MEMORY_OBJECTS=23;

_SC_AIO_LISTIO_MAX=24;

_SC_AIO_MAX=25;

_SC_AIO_PRIO_DELTA_MAX=26;

_SC_DELAYTIMER_MAX=27;

_SC_MQ_OPEN_MAX=28;

_SC_MQ_PRIO_MAX=29;

_SC_VERSION=30;

_SC_PAGESIZE=31;

_SC_RTSIG_MAX=32;

_SC_SEM_NSEMS_MAX=33;

_SC_SEM_VALUE_MAX=34;

_SC_SIGQUEUE_MAX=35;

_SC_TIMER_MAX=36;

_SC_BC_BASE_MAX=37;

_SC_BC_DIM_MAX=38;

_SC_BC_SCALE_MAX=39;

_SC_BC_STRING_MAX=40;

_SC_COLL_WEIGHTS_MAX=41;

_SC_EQUIV_CLASS_MAX=42;

_SC_EXPR_NEST_MAX=43;

_SC_LINE_MAX=44;

_SC_RE_DUP_MAX=45;

_SC_CHARCLASS_NAME_MAX=46;

_SC_2_VERSION=47;

_SC_2_C_BIND=48;

_SC_2_C_DEV=49;

_SC_2_FORT_DEV=50;

_SC_2_FORT_RUN=51;

_SC_2_SW_DEV=52;

_SC_2_LOCALEDEF=53;

_SC_PII=54;

_SC_PII_XTI=55;

_SC_PII_SOCKET=56;

_SC_PII_INTERNET=57;

_SC_PII_OSI=58;

_SC_POLL=59;

_SC_SELECT=60;

_SC_UIO_MAXIOV=61;

_SC_IOV_MAX=62;

_SC_PII_INTERNET_STREAM=63;




_SC_PII_INTERNET_DGRAM=64;

_SC_PII_OSI_COTS=65;

_SC_PII_OSI_CLTS=66;

_SC_PII_OSI_M=67;

_SC_T_IOV_MAX=68;

_SC_THREADS=69;

_SC_THREAD_SAFE_FUNCTIONS=70;

_SC_GETGR_R_SIZE_MAX=71;

_SC_GETPW_R_SIZE_MAX=72;

_SC_LOGIN_NAME_MAX=73;

_SC_TTY_NAME_MAX=74;

_SC_THREAD_DESTRUCTOR_ITERATIONS=75;

_SC_THREAD_KEYS_MAX=76;

_SC_THREAD_STACK_MIN=77;

_SC_THREAD_THREADS_MAX=78;

_SC_THREAD_ATTR_STACKADDR=79;

_SC_THREAD_ATTR_STACKSIZE=80;

_SC_THREAD_PRIORITY_SCHEDULING=81;

_SC_THREAD_PRIO_INHERIT=82;

_SC_THREAD_PRIO_PROTECT=83;

_SC_THREAD_PROCESS_SHARED=84;

_SC_NPROCESSORS_CONF=85;

_SC_NPROCESSORS_ONLN=86;

_SC_PHYS_PAGES=87;

_SC_AVPHYS_PAGES=88;

_SC_ATEXIT_MAX=89;

_SC_PASS_MAX=90;

_SC_XOPEN_VERSION=91;

_SC_XOPEN_XCU_VERSION=92;

_SC_XOPEN_UNIX=93;

_SC_XOPEN_CRYPT=94;

_SC_XOPEN_ENH_I18N=95;

_SC_XOPEN_SHM=96;

_SC_2_CHAR_TERM=97;

_SC_2_C_VERSION=98;

_SC_2_UPE=99;

_SC_XOPEN_XPG2=100;

_SC_XOPEN_XPG3=101;

_SC_XOPEN_XPG4=102;

_SC_CHAR_BIT=103;

_SC_CHAR_MAX=104;

_SC_CHAR_MIN=105;

_SC_INT_MAX=106;

_SC_INT_MIN=107;

_SC_LONG_BIT=108;

_SC_WORD_BIT=109;

_SC_MB_LEN_MAX=110;

_SC_NZERO=111;

_SC_SSIZE_MAX=112;

_SC_SCHAR_MAX=113;

_SC_SCHAR_MIN=114;

_SC_SHRT_MAX=115;

_SC_SHRT_MIN=116;

_SC_UCHAR_MAX=117;

_SC_UINT_MAX=118;

_SC_ULONG_MAX=119;

_SC_USHRT_MAX=120;

_SC_NL_ARGMAX=121;

_SC_NL_LANGMAX=122;

_SC_NL_MSGMAX=123;

_SC_NL_NMAX=124;

_SC_NL_SETMAX=125;

_SC_NL_TEXTMAX=126;

_SC_XBS5_ILP32_OFF32=127;

_SC_XBS5_ILP32_OFFBIG=128;

_SC_XBS5_LP64_OFF64=129;

_SC_XBS5_LPBIG_OFFBIG=130;

_SC_XOPEN_LEGACY=131;

_SC_XOPEN_REALTIME=132;

_SC_XOPEN_REALTIME_THREADS=133;

_SC_ADVISORY_INFO=134;

_SC_BARRIERS=135;

_SC_BASE=136;

_SC_C_LANG_SUPPORT=137;

_SC_C_LANG_SUPPORT_R=138;



_SC_CLOCK_SELECTION=139;

_SC_CPUTIME=140;

_SC_THREAD_CPUTIME=141;

_SC_DEVICE_IO=142;

_SC_DEVICE_SPECIFIC=143;

_SC_DEVICE_SPECIFIC_R=144;

_SC_FD_MGMT=145;

_SC_FIFO=146;

_SC_PIPE=147;

_SC_FILE_ATTRIBUTES=148;

_SC_FILE_LOCKING=149;

_SC_FILE_SYSTEM=150;

_SC_MONOTONIC_CLOCK=151;

_SC_MULTI_PROCESS=152;

_SC_SINGLE_PROCESS=153;

_SC_NETWORKING=154;

_SC_READER_WRITER_LOCKS=155;

_SC_SPIN_LOCKS=156;

_SC_REGEXP=157;

_SC_REGEX_VERSION=158;

_SC_SHELL=159;

_SC_SIGNALS=160;

_SC_SPAWN=161;

_SC_SPORADIC_SERVER=162;

_SC_THREAD_SPORADIC_SERVER=163;

_SC_SYSTEM_DATABASE=164;

_SC_SYSTEM_DATABASE_R=165;

_SC_TIMEOUTS=166;

_SC_TYPED_MEMORY_OBJECTS=167;

_SC_USER_GROUPS=168;

_SC_USER_GROUPS_R=169;

_SC_2_PBS=170;

_SC_2_PBS_ACCOUNTING=171;

_SC_2_PBS_LOCATE=172;

_SC_2_PBS_MESSAGE=173;

_SC_2_PBS_TRACK=174;

_SC_SYMLOOP_MAX=175;

_SC_STREAMS=176;

_SC_2_PBS_CHECKPOINT=177;

_SC_V6_ILP32_OFF32=178;

_SC_V6_ILP32_OFFBIG=179;

_SC_V6_LP64_OFF64=180;

_SC_V6_LPBIG_OFFBIG=181;

_SC_HOST_NAME_MAX=182;

_SC_TRACE=183;

_SC_TRACE_EVENT_FILTER=184;

_SC_TRACE_INHERIT=185;

_SC_TRACE_LOG=186;

type struct=record

name:integer;

value:string;

end;

function sysconf(name:integer):longint;cdecl;external 'c';

const

count=20;

mas:array [1..count] of struct=(

(name:_SC_ARG_MAX;value:' exec'),

(name:_SC_CHILD_MAX;value:' '),

(name: _SC_CLK_TCK;value:' exec'),

(name:_SC_NGROUPS_MAX;value:' exec'),



(name:_SC_OPEN_MAX;value:' exec'),

(name:_SC_STREAM_MAX;value:' exec'),



(name:_SC_TZNAME_MAX;value:' exec'),

(name:_SC_JOB_CONTROL;value:' exec'),



(name:_SC_ARG_MAX;value:' exec'),

(name:_SC_SAVED_IDS;value:' exec'),

(name:_SC_REALTIME_SIGNALS;value:' exec'),

(name:_SC_PRIORITY_SCHEDULING;value:' exec'),



(name:_SC_TIMERS;value:' exec'),

(name:_SC_ASYNCHRONOUS_IO;value:' exec'),

(name:_SC_PRIORITIZED_IO;value:' exec'),

(name:_SC_SYNCHRONIZED_IO;value:' exec'),



(name:_SC_FSYNC;value:' exec'),

(name:_SC_MAPPED_FILES;value:' exec'),

(name:_SC_MEMLOCK;value:' exec'),

(name:_SC_MEMLOCK_RANGE;value:' exec')

(name:_SC_MEMORY_PROTECTION;value:' exec'),

(name:_SC_CHILD_MAX;value:' '),

(name:_SC_MESSAGE_PASSING;value:' exec'),

(name:_SC_SEMAPHORES;value:' exec'),



(name:_SC_SHARED_MEMORY_OBJECTS;value:' exec'),

(name:_SC_AIO_LISTIO_MAX;value:' '),

(name:_SC_AIO_MAX;value:' exec'),

(name:_SC_AIO_PRIO_DELTA_MAX;value:' exec'),



(name:_SC_DELAYTIMER_MAX;value:' exec'),



(name:_SC_MQ_OPEN_MAX;value:' '),

(name:_SC_MQ_PRIO_MAX;value:' exec'),

(name:_SC_VERSION;value:' exec'),



(name:_SC_PAGESIZE;value:' exec'),

(name:_SC_RTSIG_MAX;value:' '),

(name:_SC_SEM_NSEMS_MAX;value:' exec'),

(name:_SC_SEM_VALUE_MAX;value:' exec'),



(name:_SC_SIGQUEUE_MAX;value:' exec'),

(name:_SC_TIMER_MAX;value:' '),

(name:_SC_BC_BASE_MAX;value:' exec'),

(name:_SC_BC_DIM_MAX;value:' exec'),



(name:_SC_BC_SCALE_MAX;value:' exec'),

(name:_SC_BC_STRING_MAX;value:' '),

(name:_SC_COLL_WEIGHTS_MAX;value:' exec'),

(name:_SC_EQUIV_CLASS_MAX;value:' exec'),



(name:_SC_EXPR_NEST_MAX;value:' exec'),

(name:_SC_LINE_MAX;value:' '),

(name:_SC_RE_DUP_MAX;value:' exec'),

(name:_SC_CHARCLASS_NAME_MAX;value:' exec'),



(name:_SC_2_VERSION;value:' exec'),

(name:_SC_2_C_BIND;value:' '),

(name:_SC_2_C_DEV;value:' exec'),

(name:_SC_2_FORT_DEV;value:' exec'),





(name:_SC_2_FORT_RUN;value:' exec'),

(name:_SC_2_SW_DEV;value:' '),

(name:_SC_2_LOCALEDEF;value:' exec'),

(name:_SC_PII;value:' exec'),



(name:_SC_PII_XTI;value:' exec'),

(name:_SC_PII_SOCKET;value:' '),

(name:_SC_PII_INTERNET;value:' exec'),

(name:_SC_PII_OSI;value:' exec'),



(name:_SC_POLL;value:' exec'),

(name:_SC_SELECT;value:' '),

(name:_SC_UIO_MAXIOV;value:' exec'),

(name:_SC_IOV_MAX;value:' exec'),



(name:_SC_PII_INTERNET_STREAM;value:' exec'),

(name:_SC_PII_INTERNET_DGRAM;value:' '),

(name:_SC_PII_OSI_COTS;value:' exec'),

(name:_SC_PII_OSI_CLTS;value:' exec'),



(name:_SC_PII_OSI_M;value:' exec'),

(name:_SC_T_IOV_MAX;value:' '),

(name:_SC_THREADS;value:' exec'),

(name:;value:' exec'),



(name:;value:' exec'),

(name:;value:' '),

(name:;value:' exec'),

(name:;value:' exec'),





);

var

i:integer;

begin

for i:=1 to count do

writeln(mas[i].value,' = ',sysconf(mas[i].name));

end.

 

L 13.53. = , 𦕺 v v v .

program Parameters;

uses Dos,Crt;

var

i:Byte;

begin

ClrScr;

if ParamCount>1 then

begin

Writeln('Owner parameters:');

For i:=1 to ParamCount do

Writeln(Paramstr(i));

end

else Writeln('No owner parameters.');

Writeln('System parameters:');

if envcount<10 then

for i := 1 to EnvCount do

Writeln(EnvStr(i))

else

for i := 1 to 10 do

Writeln(EnvStr(i));

end.

 

L 13.54. = , 𦕺 v v𦕺: , , v, , .

uses linux;

function getnamebyuid(uid:longint):string;

var

f:text;

s,name:string;

n,res:integer;

begin

assign(f,'/etc/passwd');

reset(f);

while not eof(f) do

begin

readln(f,s);

n:=pos(':',s);

name:=copy(s,1,n-1);

delete(s,1,n+2);

n:=pos(':',s);

delete(s,n,length(s)-n+1);

val(s,res);

if uid=res then

begin

getnamebyuid:=name;

exit;

end;

end;

getnamebyuid:='';

end;

var

pid,uid,gid:longint;

name,term:string;

t:termios;

begin

pid:=getpid;

uid:=getuid;

gid:=getgid;

name:=getnamebyuid(uid);

term:=getenv('TERM');

tcgetattr(0,t);

writeln('= - ',pid);

writeln(' ',uid, ' ',name);

writeln(' ',gid);

write(' v ');

if (t.c_lflag and ICANON)=0 then

write('');

writeln(' ',term);

end.

L 13.55. = , v v v 𦕺 v .



uses crt,dos;

var i:integer;

s,st:array[0..200]of char;



c:char;

function setenv(s1,s2:pchar;ower:integer):integer;cdecl;external 'c';

begin

for i:=1 to envcount do

writeln(envstr(i),'=',getenv(envstr(i)));

writeln(' T , .');

readln(s);

if getenv(strpas(s))<>'' then

writeln(getenv(strpas(s)))

else

begin

writeln(' ',s,' ');

halt;

end;

writeln('- ',s,' "y" ');

c:=readkey;

if upcase(c)='Y' then

begin

writeln('T ');

readln(st);

if setenv(s,st,1)<0 then

writeln(' ')

else

writeln(setenv(s,st,1),' ',getenv(strpas(s)));

end;

end.

L 13.56. = sleep(n), 𦕺 v v n . T v v alarm(n) () v pause(), v . , SIGALRM. T alarm, v v sleep (alarm v , v ).

uses dos,crt,sysutils,linux;



procedure handler(sig:integer);cdecl;

begin

end;



procedure sleep(count:integer);

var

oldhandler,newhandler:sigactionrec;

begin



writeln('count=',count);

newhandler.handler.sh:=@handler;

(*newhandler.sa_mask:=$ffffffff;*)

newhandler.sa_mask:=0;

sigaction(SIGALRM,@newhandler,@oldhandler);

alarm(count);

pause;

sigaction(SIGALRM,@oldhandler,nil);

end;

begin

repeat

sleep(3);

writeln('');

until keypressed;

end.


    





Forekc.ru
, , , , , , , , , ,